Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

Select an Option from the Right-Click Menu in Selenium Webdriver - Java

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

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.

Please Help!!!

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...