Action Class in Selenium WebDriver – Mouse Hover, Click & Double Click
By Bhau Automation • Selenium Action Class Tutorial
🎯 What You Will Learn
- What is the Actions class in Selenium WebDriver
- How to perform mouse hover action
- How to perform click action using Actions class
- How to perform double click action
- Handling keyboard and mouse events in Selenium
- Real-time examples using Selenium WebDriver
💡 Practice Selenium automation on our demo website: https://www.bhauautomation.com → Services → Selenium Automation Practice Page.
📌 What is Action Class in Selenium?
The Actions class in Selenium WebDriver is used to perform complex user interactions like mouse hover, right click, drag and drop, double click, and keyboard events.
These advanced user interactions are handled using the org.openqa.selenium.interactions.Actions class.
💻 How to Perform Mouse Hover in Selenium
Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.id("menu"));
actions.moveToElement(menu).perform();
🖱 Perform Click Action Using Actions Class
Actions actions = new Actions(driver);
WebElement button = driver.findElement(By.id("submit"));
actions.click(button).perform();
🖱 Perform Double Click Action
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("doubleClickBtn"));
actions.doubleClick(element).perform();
⌨ Keyboard Actions Example
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();
🔄 Common Mouse Actions in Selenium
- Mouse Hover – moveToElement()
- Click – click()
- Double Click – doubleClick()
- Right Click – contextClick()
- Drag and Drop – dragAndDrop()
🎯 Real-World Use Cases
- Handling dropdown menus that appear on hover
- Performing drag and drop operations
- Automating context menu interactions
- Complex UI testing scenarios
❓ Interview Questions
Q: What is Actions class in Selenium?
A: Actions class is used to perform advanced user interactions like mouse hover, drag and drop, double click, and keyboard actions.
Q: Which method is used for mouse hover?
A: moveToElement()
🎥 Watch the Complete Tutorial
👉 Watch on YouTube: Action Class in Selenium WebDriver
🎓 Key Takeaways
- Actions class handles advanced mouse and keyboard interactions
- moveToElement() is used for mouse hover
- click() and doubleClick() simulate user mouse actions
- Important concept in Selenium automation frameworks
🚀 Created with ❤️ by Bhau Automation