import os
import time
import random
import webbrowser
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
binary = 'C:/Users/lee/Documents/IEDriverServer.exe'
browser = webdriver. Ie (binary)
browser.set_window_size(533,533)
browser.get('https://www.naver.com/')
time.sleep(10)
browser.quit()
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
A couple of points :
- Keep the required
imports
only. Remove the unwantedimports
to keep things simpler. - Need to be careful with extra spaces as
Python
is sensitive tospaces
andindents
. - To mention
OS
paths either use escaped back slashes(\\)
or use single front slashes(/)
along with the raw(r)
switch. Here is your own working code with some minor tweaks:
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import time cap = DesiredCapabilities().INTERNETEXPLORER cap['ignoreProtectedModeSettings'] = True browser = webdriver.Ie(capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\IEDriverServer.exe") browser.get('https://www.naver.com/') browser.set_window_size(533,533) time.sleep(10) browser.quit()
Update
As you are seeing the error as WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode set
, follow the steps below and execute your tests :
- On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
- Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog.
- The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
- For Windows 10, you also need to set "Change the size of text, apps, and other items" to 100% in display settings.