admin管理员组文章数量:1426959
Presently, the application in which I am working has got many work flows that open new window one after another. I have used the following way to switch the focus to new window:
for (String popUpHandle : driver.getWindowHandles()) {
driver.switchTo().window(popUpHandle);
if(driver.getCurrentUrl().equalsIgnoreCase(URL of the new window)
...
}
Same way, I used it with page title. Used selenium.isElementPresent present to get inside the condition and do certain operation in the new window.
The above three solutions work fine, but takes too much time in IE when in one work flow, 2-3 windows remain hidden.
Any guidance to switch focus new window as soon as we open it after we click on some link or button, would be very much appreciated.
Presently, the application in which I am working has got many work flows that open new window one after another. I have used the following way to switch the focus to new window:
for (String popUpHandle : driver.getWindowHandles()) {
driver.switchTo().window(popUpHandle);
if(driver.getCurrentUrl().equalsIgnoreCase(URL of the new window)
...
}
Same way, I used it with page title. Used selenium.isElementPresent present to get inside the condition and do certain operation in the new window.
The above three solutions work fine, but takes too much time in IE when in one work flow, 2-3 windows remain hidden.
Any guidance to switch focus new window as soon as we open it after we click on some link or button, would be very much appreciated.
Share Improve this question asked Aug 14, 2012 at 3:54 arinarin 1253 silver badges9 bronze badges1 Answer
Reset to default 5One trick to speed it up a little bit is to always ignore the parent window. So do something like:
//before any pop ups are open
String parentHandle = driver.getWindowHandle();
//after you have pop ups
for (String popUpHandle : driver.getWindowHandles()) {
if(!popUpHandle.equals(parentHandle)){
driver.switchTo().window(popUpHandle);
if(driver.getCurrentUrl().equalsIgnoreCase(URL of the new window)){
//do something here
}
}
}
You can also switch to the most recent opened window this way since the collection should be ordered (* I think, don't have access to a Selenium set up to test at the moment *):
String newWindowHandle = driver.getWindowHandles()[driver.getWindowHandles().length - 1];
driver.switchTo().window(newWindowHandle);
Finally, not sure which version of Selenium you're using but the latest IEDriver is significantly faster: http://code.google./p/selenium/wiki/InternetExplorerDriver
本文标签: javaHow to switch to new window without using seleniumwebdriver methodsStack Overflow
版权声明:本文标题:java - How to switch to new window without using seleniumwebdriver methods - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745356131a2655063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论