2

I'm trying to select an option from context menu, and sendKeys(Keys.ARROW_DOWN) is not working. All it does is that it moves the scroll of the page up and down(even though context menu is still open)

Actions action = new Actions(driver);
action.contextClick(element).build().perform();
action.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.Enter).build().perform();

the sendKeys method here just moves the page up and down without taking the opened context menu into consideration.(I also tried switching to an alert) Is there another way to select an option from the context menu?

3

2 Answers 2

1

try this code :

action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.Enter).build().perform();
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your suggestion, Tried it, the context menu does open, but the sendKeys(Keys.ARROW_DOWN) moves the scroll of the page down as if the context menu is not open.
then after context click , you have to find the element (whichever you wanna select) by any locators and click on it ! Please update your question with html of options you are getting after right click !
This context menu is not a part of html page, it is a menu coming from Chrome (a desktop application), so context menu options don't appear in the html. Manually after opening the context menu, pressing the up or down arrows then pressing enter on the keyboard works for selecting an option from the context menu. But when I run the code I wrote it just scrolls the page up and down(the focus is still on the page and not on the context menu itself).
Please share the html of 1. Element you are right clicking 2. What are the options available 3. Your desire output
0

To navigate the context menu, you have to press the shift key AND arrow keys. Like this:

actionChains.context_click(element).send_keys(Keys.SHIFT, Keys.ARROW_DOWN, 'H')

The thing I have trouble with though is how to navigate down more than one menu item. Mine just always stops at the second item

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.