tic
tic

Reputation: 83

Robot Framework - set Protected Mode settings for IE

I'm encountering the following error: "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)." when opening IE using Selenium WebDriver.

In Java (using selenium-server 3.8.1), I solved this by using:

InternetExplorerOptions options = new InternetExplorerOptions();
options.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(options);

How do I do this for Robot Framework (using Java port of SeleniumLibrary: robotframework-seleniumlibrary-3.8.1.0-jar-with-dependencies)?

${ie_options}=    Create Dictionary    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS=true
Open Browser    ${url}    ie    None    None    ${ie_options}   None

I tried the one above but I still encounter the error. Changed it to ignoreProtectedModeSettings to no avail. Any ideas?

Upvotes: 1

Views: 1486

Answers (3)

ajain
ajain

Reputation: 344

I was facing the same issue and tried to use Dinesh Pundkar's answer but it did not work. Finally, I was able to find this https://stackoverflow.com/a/63543398/3297490 and it worked like a charm.

One thing to note however, after running the vbs script I checked in the IE settings and the protected mode settings were still shown the way they were and they did not really come back to the normal levels.

Upvotes: 0

TurnipEntropy
TurnipEntropy

Reputation: 527

To do this directly in the Robot Framework:

${ie_dc} =      Evaluate  
    ...         sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER 
    ...         sys, selenium.webdriver
${ieOptions} =  Create Dictionary  ignoreProtectedModeSettings=${True}
Set To Dictionary   ${ie_dc}  se:ieOptions  ${ieOptions}
Open Browser    ${url}  ie  desired_capabilities=${ie_dc}

At some point the ignoreProtectedModeSettings got placed inside the se:ieOptions dictionary within the capabilities dictionary. You can see this if you debug Selenium's Python library, specifically webdriver/remote/webdriver.py and look at the response in start_session.

Upvotes: 0

Dinesh Pundkar
Dinesh Pundkar

Reputation: 4196

I have written Custom Keyword which updates the Windows Registry to enable ProtectedMode for all Zones.

Below is Python code :

from winreg import *

def Enable_Protected_Mode():
    """
    # 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".
    """
    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)
    except Exception:
        print("Failed to enable protected mode")

You can write the same code in Java.Check here for more help !!!

Upvotes: 1

Related Questions