2

When i started using Selenium i found it difficult to perform actions (hover,click..etc) on hidden elements, which becomes visible only when hovered on some other element. so i hope this will help others, you can use any of the following ways..

For example, to upvote a comment in this page,i need to hover on the context (i.e. comment) to make upward arrow visible, then i need to click on it. But using javascriptExcecuter you can execute this in one step.

1 Answer 1

1
//this can be used even if the element is not visible
//if you want to hover over the element, replace click() with hover() 
((JavascriptExecutor)driver).executeScript("$('element_selector').click();");

OR

you can use Actions class rather than using the Keyboard or Mouse directly. 
It implements the builder pattern: Builds a CompositeAction containing all actions specified by method calls

More info on Action class can be found here.

Sign up to request clarification or add additional context in comments.

3 Comments

Keyboard, Mouse and TouchScreen have all been deprecated and removed from WebDriver with the last patch: code.google.com/p/selenium/source/browse/java/CHANGELOG
i could never imagine a user story that requires that the user hovers over a hidden element to make something happen.. it's preposterous - but interesting :P
actually in the scenario that i have mentioned , there are 2 elements, user will have to hover on one element to make the other element visible...which means the first element has to be visible for this to work..

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.