How to perform mouse hovering in Selenium WebDriver (Java)?

0 votes

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,070 points
2,336 views

1 answer to this question.

0 votes

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,050 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.

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,050 points
3,350 views
+9 votes
13 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,280 points
47,344 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 in Selenium by Surya
• 950 points
56 views
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
6,337 views
0 votes
1 answer

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,050 points
258 views
0 votes
1 answer
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,130 points
624 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
250 views
0 votes
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,050 points
1,609 views
0 votes
1 answer

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

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
5,741 views