I am facing a problem automating the protection settings in IE using Selenium with python
.
I found a solution to automate the settings in java but it is not working when i changed it to python .
I tried the following::
from selenium import webdriver
caps=webdriver.DesiredCapabilites.INTERNETEXPLORER
caps['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS']=True
driver=webdriver.Ie(caps)
This gave an error with respect to the argument given .
and when I used driver = webdriver.Ie()
It says protection mode settings must be same for all zones.
Can anyone help me automate this thing using selenium in python.
According to documentation, in python-selenum, you should use setting called
ignoreProtectedModeSettings
:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True
driver = webdriver.Ie(capabilities=caps)
Desired capabilities doesn't work in some instances. Here is a method to change protection settings from the registry using winreg.
from winreg import *
def Enable_Protected_Mode():
# SECURITY ZONES ARE AS FOLLOWS:
# 0 is the Local Machine zone
# 1 is the Intranet zone
# 2 is the Trusted Sites zone
# 3 is the Internet zone
# 4 is the Restricted Sites zone
# CHANGING THE SUBKEY VALUE "2500" TO DWORD 0 ENABLES PROTECTED MODE FOR THAT ZONE.
# IN THE CODE BELOW THAT VALUE IS WITHIN THE "SetValueEx" FUNCTION AT THE END AFTER "REG_DWORD".
#os.system("taskkill /F /IM iexplore.exe")
try:
keyVal = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1'
key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS)
SetValueEx(key, "2500", 0, REG_DWORD, 0)
print("enabled protected mode")
except Exception:
print("failed to enable protected mode")