简体   繁体   English

getWindowHandles 方法使用 MS EDGE IE11 和 Selenium 版本 4.1.2 返回错误数量的 window 句柄

[英]getWindowHandles method returns incorrect number of window handles using MS EDGE IE11 and Selenium version 4.1.2

Recently, I have upgraded my Selenium version from 2.53 to 4.1.2 to enable testing of our application on MS EDGE IE11.最近,我将我的 Selenium 版本从 2.53 升级到 4.1.2,以便能够在 MS EDGE IE11 上测试我们的应用程序。 But we are intermittently facing issues while retrieving number of windows open in MS EDGE IE11 with selenium-4.1.2但是我们在使用 selenium-4.1.2 检索在 MS EDGE IE11 中打开的 windows 数量时间歇性地面临问题

Did anyone else facing similar kind of issues with Selenium-4.1.2?还有其他人遇到过与 Selenium-4.1.2 类似的问题吗?

Below is piece of code I have tried on MS EDGE IE11.下面是我在 MS EDGE IE11 上试过的一段代码。 Sometimes we could see its returning correct no.有时我们可以看到它返回正确的号码。 of windows but sometime not. windows 但有时不是。 We are also using sufficient wait-time before retrieving number of windows.在检索号码 windows 之前,我们还使用了足够的等待时间。

Note - This is working absolutely fine on IE11 browser with Selenium-4.1.2注意 - 这在带有 Selenium-4.1.2 的 IE11 浏览器上工作得很好

int noOfWindowsOpen = driver.getWindowHandles().size();

Expectation: It should always return correct value of no.期望:它应该总是返回正确的值 no。 of windows open. windows 打开。

Once you open the new tab / window before you count the number of WindowHandles you need to induce WebDriverWait for numberOfWindowsToBe() as follows:打开新选项卡 / window后,在计算WindowHandles的数量之前,您需要为numberOfWindowsToBe()引入WebDriverWait ,如下所示:

driver.get("http://www.google.com");
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
new WebDriverWait(driver, 10).until(ExpectedConditions.numberOfWindowsToBe(2));
int noOfWindowsOpen = driver.getWindowHandles().size();

It seems to be a known limitation in automating Edge IE mode.这似乎是自动化 Edge IE 模式的一个已知限制 It says:它说:

To ensure the new window has been created successfully and IEDriver has detected it, you must continuously check the result of the Get Window Handles command until it contains a handle to the new window.为确保新的 window 已成功创建并且 IEDriver 已检测到它,您必须不断检查Get Window Handles命令的结果,直到它包含新的 window 的句柄。

You can try the sample code in it:你可以试试里面的示例代码:

int initialHandleCount = driver.getWindowHandles().size();
driver.findElement(By.id("<Id of the button that will open a new window>")).click();        
Set<string> newHandles = driver.getWindowHandles();
while (newHandles.size() == initialHandleCount) {
    newHandles = driver.getWindowHandles();
}

I have found a work-around for above problem.我找到了解决上述问题的方法。

Before executing, make sure all the instances of ME Edge, IE and IE Driver are closed.执行之前,请确保ME Edge、IE和IE Driver的所有实例都已关闭。 If not, kill them forcefully from task manager and then re-run the Test Script.如果没有,请从任务管理器中强制杀死它们,然后重新运行测试脚本。 Script will identify the new window properly.脚本将正确识别新的 window。

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 clear() 方法不会使用 Selenium-4.1.2 清除 MS EDGE IE11 中的字段 - clear() method doesn't clears the field in MS EDGE IE11 with Selenium-4.1.2 Selenium IE驱动程序在同一窗口的多个选项卡上使用getWindowHandles方法时将选项卡数返回1 - Selenium IE driver returns tab count as 1 while using getWindowHandles method on multiple tabs of same window C# IE11 selenium webdriver,新选项卡没有新窗口句柄 - C# IE11 selenium webdriver, No new window handles with new tab 使用Selenium在IE11中关闭第n个打开的窗口 - Close nth open window in IE11 using Selenium Driver.getWindowHandles() 在 Windows 10 上的 IE11 中始终返回 1 - Driver.getWindowHandles() is always returning 1 in IE11 on Windows 10 如何使用 Selenium 绑定指定 IE11 和边缘浏览器的下载位置 - How to spcify the download location for IE11 and edge browsers using Selenium bindings IE11和Selenium 3.13的IEDriverServer的兼容版本是哪个? - Which is the compatible version of IEDriverServer for IE11 and Selenium 3.13? 与JDK 1.6一起运行的IE11应用程序的硒版本 - Selenium version for IE11 application running with JDK 1.6 硒中的3-4个子窗口(使用getwindowhandles方法) - 3-4 child windows in selenium by using getwindowhandles method IE11上的Selenium WebDriver - Selenium WebDriver on IE11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM