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

前端 未结 2 1009
鱼传尺愫
鱼传尺愫 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条回答
  • Just wanted to give an update, in case anyone else has this same problem and finds this page. I haven't found a solution to my problem, but I came up with a workaround.

    Originally, I was clicking on a link that opened a new window, and I was having trouble navigating Selenium to the new window. What I did instead was dig through the page's source code, find the button that I was clicking on, and figure out where that button points to. It would have been easiest if it was a simple hyperlink (www.whatever.com/....), but instead it was a Javascript function. That Javascript function builds up the hyperlink using some fixed characters and some variables; for example:

    link(username, date) = "http://www.google.com/user=" + username + "?date=" + date;
    

    So, going along with this example, I just figured out what variables were being fed in (username, date, etc.), built the URL myself, and navigated to it directly. Thus I didn't even have to open up and navigate to a new window at all.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题