所以我有一个测试运行点击一个链接,但该链接打开一个新的broswer窗口。如何在硒中驱动新的broswer实例?就像是否有我可以使用的特定方法,或者我可以创建一个新的selenium对象来驱动新的broswer实例?我很欣赏一个例子
答案 0 :(得分:1)
因此,点击链接后,请执行以下操作:
//Get the parent window handle
String parentHandle = driver.getWindowHandle();
for(String handle : driver.getWindowHandles())
{
driver.switchTo().window(handle);
//Since window handles are random in order, verify whether you are on the correct page
if(driver.getTitle().equalsIgnoreCase(<Title of the new page>))
{
//do whatever you wish to do on this page
//once done, you may need to close this page
driver.close();
break;
}
}
//Switch back to the parent page
driver.switchTo().window(parentHandle);
答案 1 :(得分:0)
您可以使用窗口处理程序导航到新窗口,然后与新窗口中的元素进行交互。