从 Selenium Webdriver 的右键菜单中选择一个选项 - Java [英] Select an Option from the Right-Click Menu in Selenium Webdriver - Java

查看:36
本文介绍了从 Selenium Webdriver 的右键菜单中选择一个选项 - Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium 网络驱动程序.我无法从右键单击打开的选项中选择(比如第二个)选项.

I am using Selenium webdriver. I am not able to select (say 2nd) option from the Options opened on right click.

在我当前的代码中,我可以右键单击 webElement,但无法从右键单击后打开的列表中选择一个选项,因为它会自动消失.

In my current code I am able to right click on webElement but could not select an Option from the list that is opened after right click, as it disappears automatically.

Actions action= new Actions(driver);
action.contextClick(productLink).build().perform();

因此,使用此代码,我可以右键单击,但右键单击菜单会自动消失.我想从右键菜单中选择说第二个选项.

So with this code I am able to right click but the right click menu automatically disappears. I want to select say 2nd Option from Right click menu.

请帮忙!!!

推荐答案

要从上下文菜单中选择项目,您只需使用 Key down 事件移动鼠标位置,如下所示:-

To select the item from the contextual menu, you have to just move your mouse positions with the use of Key down event like this:-

Actions action= new Actions(driver);
action.contextClick(productLink).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();

希望这对你有用.祝你有美好的一天:)

hope this will works for you. Have a great day :)

这篇关于从 Selenium Webdriver 的右键菜单中选择一个选项 - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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