Java – selenium does not detect the second window in ie

My application opens a new button - click window where I need to do something However, selenium webdriver's response to getWindowHandles () method has only one window. ID., if getWindowHandles () is delayed after opening the new window, this happens. Selenium has known problems

But even the solution doesn't work for me

The code is as follows

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
RemoteWebDriver driver = new
        RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capabilities);

driver.get("https://<url>");

WebElement userName = driver.findElement(By.name("usr_name"));
userName.sendKeys("ABCD");

WebElement password = driver.findElement(By.name("usr_password"));
password.sendKeys("password");

WebElement login = driver.findElement(By.name("OK"));
login.click();  


WebElement popup= driver.findElement(By.name("popup"));
popup.click();      

Thread.sleep(1000);

Set<String> windowHandles = driver.getWindowHandles();      
System.out.println(windowHandles);

Set "windowshandles" will return only one window:

"[fcdad457-9090-4dfd-8da1-acb9d6f73f74]"

But if I cancel sleep It will return two window IDS:

[90cc6006-0679-450c-a5b3-6602bcb41a16,7211bbfd-2616-4460-97e7-56c0e632c3bb]

I can't remove sleep because it's just a sample program. In a real application, there will be some delays between them Please let me know what you think This question only applies to ie11

Blue screen - home page; Gray screen – pop up window

Solution

When dealing with Internet Explorer, you should pay attention to the following points:

As you mentioned, known problems of selenium are recorded in GitHub. These problems are not problems, but the required configuration combination when dealing with Internet Explorer If these settings are not considered, Internet Explorer may not run as expected The following are essential to demonstrate the correct behavior of Internet Explorer V11:

>For IE 10 and later, enhanced protection mode must be disabled This option is located in the Advanced tab of the Internet Options dialog box. > The browser zoom level must be set to 100% so that local mouse events can be set to the correct coordinates. > You must change the size of text, apps, and other items to 100% in the display settings. > For IE 11, you need to set a registry key on the target computer so that the driver can maintain the connection to the Internet Explorer instance it creates

For 32-bit Windows installations,the key you have to look in the registry is : 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

For 64-bit Windows installations,the key is :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

The FEATURE_BFCACHE subkey may or may not be present,and should be created if it is not present.

>Native events: the advantage of using native events is that it does not rely on JavaScript sandbox and ensures that JavaScript events are propagated correctly in the browser However, there are some problems with mouse events when the IE browser window has no focus and attempts to hover over the element. > Browser focus: if the window has no focus, ie itself does not seem to fully respect the windows messages we send IE browser windows (wm_mousedown and wm_mouseup). > You can find detailed discussions about native events and browser focus here. > Now you must configure all these parameters through the desiredcapabilities class, as follows:

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("ignoreProtectedModeSettings",1);
cap.setCapability("IntroduceInstabilityByIgnoringProtectedModeSettings",true);
cap.setCapability("nativeEvents",true);
cap.setCapability("browserFocus",true);
cap.setCapability("ignoreZoomSetting",true);
cap.setCapability("requireWindowFocus","true");
cap.setCapability("INTRODUCE_FLAKINESS_BY_IGNORING_Security_DOMAINS",true);

>Thread. According to best programming practices sleep(1000); Now, you know that browser clients lag behind webdriver instances, so we must synchronize them often Therefore, before collecting windowshandles, you must guide webdriverwait as follows, where you can find the detailed discussion here:

WebElement popup= driver.findElement(By.name("popup"));
popup.click();
new webdriverwait(driver,5).until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> windowHandles = driver.getWindowHandles();      
System.out.println(windowHandles);

to update

I can see from your comments:

"Enable Enhanced Protected Mode" is unchecked in IE options. – Renjith Jan 9 at 7:26

The following is an article published by @ Jim Evans sentitional blog on protected mode settings and the capabilities hack, in which @ Jim Evans points out the background in clear terms:

The following is how to set the protection mode setting:

>This is another discussion of selenium ieserverdriver not finding new windows for IE9, where the solution is to turn on compatibility mode

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>