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
• 9,070 points
1,859 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,030 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,030 points
2,302 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
36,362 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
4,541 views
0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
126 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,030 points
76 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
448 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
56 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,030 points
1,237 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,030 points
4,477 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.