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
• 10,950 points
6,693 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();
answered Apr 3, 2018 by nsv999
• 5,510 points

edited Apr 4, 2018 by nsv999
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 5, 2018 in Selenium by nsv999
• 5,510 points
7,428 views
+10 votes
15 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
119,545 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 13, 2019 in Selenium by Surya
• 970 points
1,556 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
• 27,930 points
913 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,510 points
3,568 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,571 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,890 points
2,617 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 2 in Selenium by Sri
• 2,970 points
2,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,510 points
4,373 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 5 in Selenium by Sri
• 2,970 points
13,296 views