我已经看到很多关于如何在新选项卡中打开链接的线索,但是如果您有一个创建新选项卡的链接并且您需要验证标题呢?我需要做的就是点击链接 – >验证新标签是否具有正确的标题 – >关闭选项卡并继续在原始选项卡上.在此先感谢您的帮助!
解决方法:
//Get Current Page
String currentPageHandle = driver.getWindowHandle();
linkToClick.click();
//Add Logic to Wait till Page Load
// Get all Open Tabs
ArrayList<String> tabHandles = new ArrayList<String>(driver.getWindowHandles());
String pageTitle = "ThePageTitleIhaveToCheckFor";
boolean myNewTabFound = false;
for(String eachHandle : tabHandles)
{
driver.switchTo().window(eachHandle);
// Check Your Page Title
if(driver.getTitle().equalsIgnoreCase(pageTitle))
{
// Report ur new tab is found with appropriate title
//Close the current tab
driver.close(); // Note driver.quit() will close all tabs
//Swithc focus to Old tab
driver.switchTo().window(currentPageHandle);
myNewTabFound = true;
}
}
if(myNewTabFound)
{
// Report page not opened as expected
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。