Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
6 views
in DevOps and Agile by (19.7k points)

I want to do a mouseover function over a drop-down menu. When we hover over the menu, it will show the new options. I tried to click the new options using the XPath. But cannot click the menus directly. So, as the manual way, I am trying to hover over the drop-down menu and then will click the new options.

Actions action = new Actions(webdriver);

WebElement we = webdriver.findElement(By.xpath("//html/body/div[13]/ul/li[4]/a"));

action.moveToElement(we).build().perform();

1 Answer

0 votes
by (62.9k points)

To carry out this task of mouse hovering over a web-element Selenium, we use the Actions class. The Actions class provided by Selenium Webdriver is used to generate complex user gestures including mouseover, right-click, double click, drag, and drop, etc.

Code snippet to mouseover

 Actions action = new Actions(driver);

WebElement element = driver.findElement(By.id("elementId"));

action.moveToElement(element).perform();

Here, we are instantiating an object(named: action) of Actions class. After that, we pass the WebElement(located using id) to be mouse hovered as a parameter to the moveToElement() method present in the Actions class. Then, we will call the perform() method to perform the generated action.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...