Change registry for IE:

- HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ Main
- Right click -> New -> String Value -> Value Name: TabProcGrowth (create if doesn't exist)
- TabProcGrowth (right-click) โ Change ... โ Value data: 0
Source: Problem switching Windows Selenium WebDriver in Internet Explorer 8-10
In my case, IE began to detect new window handles after editing the registry.
Adapted from the MSDN blog:
Tab Process Growth: Sets the speed at which IE creates new Tab processes.
Max-Number Algorithm: Specifies the maximum number of tab processes that can be performed for a single isolation session for a single-frame process at a specific mandatory integrity level (MIC). Relative values:
- TabProcGrowth = 0: tabs and frames are executed within the same process; frames are not unified by MIC levels.
- TabProcGrowth = 1: all tabs for a given frame process are executed in one tab process for a given MIC level.
Source: Opening a new tab may launch a new process using Internet Explorer 8.0
Internet Options:
- Security โ Deny Enable secure mode for all zones (Internet, Local intranet, Trusted sites, Restricted sites)
- Advanced โ Security โ Disable Enable Enhanced Protected Mode
the code:
Browser: IE11 x64 (Zoom: 100%)
OS: Windows 7 x64
Selenium: 3.5.1
WebDriver: IEDriverServer x64 3.5.1
public static String openAndSwitchToWindow(WebDriver driver, WebElement clickableElement, long waitInMillis) throws InterruptedException { String parentHandle = driver.getWindowHandle(); // Save parent window clickableElement.click(); // Open child window Thread.sleep(waitInMillis); Set<String> handles = driver.getWindowHandles(); if (handles.size() > 1) { // Check if more than 1 window is open for (String handle : handles) { driver.switchTo().window(handle); if (!parentHandle.equals(handle)) { break; } } } return parentHandle; // Returns parent window if you want to switch back } /* How to use method */ String parentHandle = SeleniumUtil.openAndSwitchToWindow(driver, linkToChildWindow, 5000); // Do things in child window driver.manage().window().maximize(); driver.close(); // Return to parent window driver.switchTo().window(parentHandle);
The above code contains an if check to make sure you are not switching to the parent window since Set<T> does not have a guaranteed order in Java . Thread.sleep() seems to increase the likelihood of success, as confirmed below.
Quote from Luc Inman-Semerau : (Developer for Selenium)
It will take time for the browser to confirm the new window, and you can go into the switchTo () loop until the popup appears.
You automatically assume that the last window returned by getWindowHandles () will be the last. This is not necessarily true, as they are not guaranteed to be returned in any order.
Source: Unable to handle popup in IE, control does not migrate to popup
Related posts:
- Switch selenium to new IE tab
- How to open a new tab in IE using selenium (java) and open the url to this tab (not a window)
silver Aug 13 '17 at 14:07 on 2017-08-13 14:07
source share