[英]How to drive a new instance of a broswer window after clicking a link selenium
So I have a test running which clicks a link but that link opens a new broswer window. 因此,我正在运行一个测试,该测试单击一个链接,但是该链接会打开一个新的浏览窗口。 How can I driver that new broswer instance in selenium?
如何驱动硒中的新浏览器实例? Like is there a particular method I can use, or could I create a new selenium object to drive that new broswer instance?
就像我可以使用一种特定的方法,还是可以创建一个新的硒对象来驱动该新的浏览器实例? I'd appreciate an example
我会很感激一个例子
So once you have clicked on the link, do this: 因此,一旦单击链接,请执行以下操作:
//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);
您可以使用窗口处理程序导航到新窗口,然后与新窗口中存在的元素进行交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.