New window handles disappearing in IE, can't switch to new window

前端 未结 2 1028
鱼传尺愫
鱼传尺愫 2021-01-07 11:46

I am using the latest version of Selenium (2.37.0) with C# in Internet Explorer 10 (using the latest 32-bit InternetExplorerDriver, 2.37.0) to log in to a webpage, click on

2条回答
  •  没有蜡笔的小新
    2021-01-07 12:21

    This is due to incorrect security settings in Internet Explorer. You need to clear the check box for Enable Protected Mode for each of the four zones in the Internet Options dialog Security tab. The four zones must match.

    Manual Method:

    1. Open Internet Explorer.
    2. Click the Tools icon or press Alt-X.
    3. Click Internet options menu item or Alt-o.
    4. Click the Security tab.
    5. Click the Internet icon.
    6. Clear the Enable Protected Mode checkbox.
    7. Click the Local intranet icon.
    8. Clear the Enable Protected Mode checkbox.
    9. Repeat for the Trusted sites and the Restricted sites.
    10. Click Apply button.
    11. Acknowledge the security risk pop up, accepting the risk.
    12. Close Internet Explorer.

    Now your InternetExplorerDriver should show the correct number of window handles and be able to switch between windows.

    In my case manual changes only lasted until I rebooted and then the settings reverted, so I recommend modifying the registry each test run to be sure.

    C# Example Using Registry:

                const string zonesPath =
                    @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\";
                const string internetZonePath = zonesPath + "3";
                const string restrictedZonePath = zonesPath + "4";
                const string name = "2500";
                const int value = 3;
                Registry.SetValue(internetZonePath, name, value, RegistryValueKind.DWord);
                Registry.SetValue(restrictedZonePath, name, value, RegistryValueKind.DWord);
    

    The zones are:

    • Local computer: 0
    • Intranet: 1
    • Trusted sites: 2
    • Internet: 3
    • Restricted sites: 4

    The path to each zone is: "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\{zone number above}.

    The name of the key is always "2500".

    The value to turn off protected mode is "3".

    To turn on protected mode set the value to "0".

    In order to get all of the handles, all the zones must be set to the same value.

提交回复
热议问题