问题
Sample Code :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
browser = webdriver.Ie(capabilities=caps)
browser.get('http://www.google.com')
Internet Explorer is not launched and I am facing the below error :
SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
I can not change the settings in the InternetExplorer. They are controlled by Admin.
I am stuck at this starting point only, can some one help ?
回答1:
To open InternetExplorer
you need to implement the following Configurations
:
- 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 forIE 10 and higher
. This option is found in theAdvanced tab
of theInternet Options
dialog. - The browser
zoom level
must be set to100%
so that the native mouse events can be set to the correct coordinates. - For
Windows 10
, you also need to setChange the size of text, apps, and other items
to 100% in display settings. - For
IE 11
only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. For 32-bit Windows installations, the key you must examine in the registry editor isHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
. For 64-bit Windows installations, the key isHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
. Please note that theFEATURE_BFCACHE subkey
may or may not be present, and should be created if it is not present. Important: Inside this key, create aDWORD
value named iexplore.exe with the value of 0.
Now, you have to setup the IEDriverServer
binary with the following settings through DesiredCapabilities
:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreProtectedModeSettings'] = True
cap['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
cap['nativeEvents'] = True
cap['ignoreZoomSetting'] = True
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
browser = webdriver.Ie(capabilities=cap, executable_path=r'C:\path\to\IEDriverServer.exe')
browser.get('http://google.com/')
来源:https://stackoverflow.com/questions/48020561/internet-explorer-not-launched-using-selenium-even-though-ignoreprotect-mode-set