How to perform mouse hovering in Selenium WebDriver Java

+1 vote

I wanna hover the mouse over a drop down menu. When I do that, it does show the new options to select from, but when I tried to click those options using xpath, I'm unable to do it. So, as an alternative, I'm manually hovering over the drop down menu and then clicking those options. Below is my code

Actions action = new Actions(webdriver);
WebElement element = webdriver.findElement(By.xpath("//html/body/div[13]/ul/li[4]/a"));
action.moveToElement(element).build().perform();
Apr 3, 2018 in Selenium by nitinrawat895
• 11,380 points
10,838 views

1 answer to this question.

+1 vote

You many not actually be able to hover the mouse rightaway. Instead, you might have to chain all the actions together. So, first hover to the element that reveals the others (dropdown), then during the same chain, move to the visible element you want to click and simply click on it. 

So, when your working with Action Chains, you need to remember to 'do it like a user would'.

Actions action = new Actions(webdriver);
WebElement element = webdriver.findElement(By.xpath("html/body/div[13]/ul/li[4]/a"));
action.moveToElement(element).moveToElement(webdriver.findElement(By.xpath("/expression-here"))).click().build().perform();


Hope this helps!

Check out this selenium online training to learn more about it.

answered Apr 3, 2018 by nsv999
• 5,500 points

edited Aug 22, 2023 by Khan Sarfaraz
Is it possible without the action class?
It is done in a convenient way using the action class.
This solution does not work for me, I get this error: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
Hey @janiemar, could you please specify when exactly are you getting this error? could you share the code snippet as well?
Did you find solution for  javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
Hi @VK, can you please share your error logs?
What forge viewer are you using @VK?

Related Questions In Selenium

0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,621 views
+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
198,414 views
0 votes
1 answer

How to get the select options using Selenium WebDriver in Java

Hey there! You should be able to get ...READ MORE

answered Jun 14, 2019 in Selenium by Surya
• 970 points
4,778 views
0 votes
1 answer

How to perform double click using mouse actions in Selenium with Python?

Hi harsh, you can use ActionChains() class ...READ MORE

answered Jul 29, 2019 in Selenium by Abha
• 28,140 points
2,271 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,793 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,198 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,281 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,909 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,418 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,992 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP