
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform mouseover function in Selenium WebDriver using Java?
A mouse hover is done on an element to fire an event on that element. If we hover on the menus of a webpage the submenus appears. Thus this event gets triggered on hovering on an element.
It is evident from the above image that on hovering over the Packages menu the color of the text changed along with the tooltip display. Selenium has the Actions class that contains multiple APIs for mouse cursor movement.
The moveToElement() method is used to perform mouse movement. We have to import org.openqa.selenium.interactions.Actions for Action class. Along with moveToElement() we have to use the perform() method to make the mouse movement.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.interactions.Actions; public class MouseHover{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); // identify element WebElement l=driver.findElement(By.xpath("//span[text()='Jobs']")); // Actions class with moveToElement() Actions a = new Actions(driver); a.moveToElement(l).perform(); System.out.println("Tooltip: "+ l.getText()); driver.quit(); } }
Output
- Related Questions & Answers
- How to perform mouseover action on an element in Selenium?
- How to select checkboxes using selenium java webdriver?
- How to handle frame in Selenium WebDriver using java?
- How to use clickandwait in Selenium Webdriver using Java?
- How to scroll down using Selenium WebDriver with Java?
- How to type in textbox using Selenium WebDriver with Java?
- How to get selected option using Selenium WebDriver with Java?
- How to handle authentication popup with Selenium WebDriver using Java?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- Switch tabs using Selenium WebDriver with Java.
- How to close child browser window in Selenium WebDriver using Java?
- How to simulate Print screen button using selenium webdriver in Java?
- How to automate gmail login process using selenium webdriver in java?
- How to automate drag & drop functionality using Selenium WebDriver Java?
Advertisements