问题描述
我正在使用Selenium webdriver。我无法从右键单击打开的选项中选择(比如说第二个)选项。
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.
请帮助!!!
推荐答案
要从上下文菜单中选择项目,您只需使用按键向下事件移动鼠标位置,如下所示: -
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中的右键菜单中选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!