无法从右键单击操作启动新标签|爪哇硒

发布于 2025-01-23 15:10:55 字数 644 浏览 2 评论 0原文

我正在尝试右键单击链接,并使用键箭头并输入以打开一个新选项卡。

问题:执行过程中未显示错误。确定该链接,并在其上右键单击。但是,该代码没有执行下箭头并输入操作。似乎无法弄清楚原因。 有人可以帮忙吗?

代码:

a.moveToElement(subfooterdriver.findElements(By.tagName("a")).get(1)).contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();

a -obj to Action类subfooterdriver-是由5个链接组成的框架

更新:

我能够通过以下代码克服问题,但我想了解第一个代码出了什么问题。

String clickonlink=Keys.chord(Keys.COMMAND,Keys.ENTER);
subfooterdriver.findElements(By.tagName("a")).get(i).sendKeys(clickonlink);
                

I'm trying to right-click on a link and use the keys arrow-down and enter to open a new tab.

Problem: No error displayed during execution. The link is identified and a right-click is made on it. however, the code is not performing the down-arrow and entering the action. Can't seem to figure out why.
Can somebody help?

Code:

a.moveToElement(subfooterdriver.findElements(By.tagName("a")).get(1)).contextClick().sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();

a - obj to action class,
subfooterdriver - is a frame consisting of 5 links

Updated:

I was able to overcome the issue with the following code but I want to understand what went wrong with the first code.

String clickonlink=Keys.chord(Keys.COMMAND,Keys.ENTER);
subfooterdriver.findElements(By.tagName("a")).get(i).sendKeys(clickonlink);
                

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2025-01-30 15:10:55

您可以在此超文本中获取链接,然后在新选项卡中打开它,如下:

//element locatore
WebElement link =driver.findElement(By.tagName("a"));
//Get Required URL
String url = link.getAttribute("href");

You can get the link inside this hyper text then open it in new tab as following :

//element locatore
WebElement link =driver.findElement(By.tagName("a"));
//Get Required URL
String url = link.getAttribute("href");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文