我可以使用Java中的Selenium Webdriver在Windows的页面标题之间切换吗?

我可以使用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);
   } 
}