我可以使用Java中的Selenium Webdriver在Windows的页面标题之间切换吗? [英] Can i switch between windows by its page title using selenium webdriver in java?
本文介绍了我可以使用Java中的Selenium Webdriver在Windows的页面标题之间切换吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
找到了与使用getDriver().getWindowHandles()在窗口之间进行切换并对其进行迭代相关的答案.
Found answers related to switching between windows using getDriver().getWindowHandles() and iterating through it.
但是我想知道是否有任何方法可以在使用Java的Selenium Webdriver中使用页面标题在窗口之间进行切换.
But I would like to know if there is any way to switch between windows using page title in selenium webdriver using java.
注意:我是Selenium Framework的新手
Note : I am a newbie to Selenium Framework
推荐答案
是的.
String your_title = "This is the Title";
String currentWindow = driver.getWindowHandle(); //will keep current window to switch back
for(String winHandle : driver.getWindowHandles()){
if (driver.switchTo().window(winHandle).getTitle().equals(your_title)) {
//This is the one you're looking for
break;
}
else {
driver.switchTo().window(currentWindow);
}
}
这篇关于我可以使用Java中的Selenium Webdriver在Windows的页面标题之间切换吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文