如何强制Selenium在新窗口中打开链接? [英] How to force Selenium to open a link in a new window?

查看:61
本文介绍了如何强制Selenium在新窗口中打开链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在新的Chrome窗口中打开网页上的链接.已经有一个问题但这似乎是针对RC的.我试过了 driver.getUserWindow().open("http ....."); 但这是行不通的.也许有一种方法可以强制Chrome对所有链接执行此操作?理想情况下,我想知道如何强制驱动程序在新窗口中打开链接.(我正在使用Java和OS Windows 7

I need to open a link on a webpage in a new Chrome Window. There was already a question but this appears to be for RC. I tried driver.getUserWindow().open("http....."); But it is not working. May be there is a way to force Chrome to do that for all links? Ideally, i would like to know how to force a driver to open a link in a new window. (i am using java and OS Windows 7

推荐答案

您可以使用Actions类执行此操作.

You can use Actions class to perform this.

Actions act = new Actions(driver);
WebElement onElement = Your element on which action has to be performed;
act.contextClick(onElement).perform();
act.sendKeys("w").perform();  // If you want the link to open in new tab then use T instead of w

希望这会有所帮助.编码愉快.

Hope this helps. Happy coding.

这篇关于如何强制Selenium在新窗口中打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆