How to Click Using Action Class in Selenium WebDriver
By Bhau Automation • Selenium Actions Class Tutorial
🎯 What You Will Learn
- How to use the Actions class in Selenium WebDriver
- How to perform click action using Actions class
- How to perform doubleClick() in Selenium
- How to perform contextClick() (Right Click)
- How to perform dragAndDrop() action
- Real-time Selenium automation examples
💡 Practice Selenium automation on our demo website: https://www.bhauautomation.com → Services → Selenium Automation Practice Page.
📌 What is Actions Class in Selenium?
The Actions class in Selenium WebDriver is used to perform advanced user interactions such as mouse hover, right click, drag and drop, keyboard actions, and clicking elements.
Sometimes normal click() does not work because elements are hidden,
overlapped, or dynamic. In such cases Selenium provides the Actions class.
🖱 Click Using Actions Class
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("button"));
actions.click(element).perform();
🖱 Double Click Example
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("doubleClick"));
actions.doubleClick(element).perform();
🖱 Right Click Example (contextClick)
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.id("rightClick"));
actions.contextClick(element).perform();
🖱 Drag and Drop Example
Actions actions = new Actions(driver);
WebElement source = driver.findElement(By.id("drag"));
WebElement target = driver.findElement(By.id("drop"));
actions.dragAndDrop(source, target).perform();
🔄 Important Mouse Actions Methods
- click() – Click on element
- doubleClick() – Double click action
- contextClick() – Right click action
- dragAndDrop() – Drag element and drop to target
🎯 Real-World Use Cases
- Handling complex UI interactions
- Clicking hidden or dynamic elements
- Automating drag and drop functionality
- Handling right-click context menus
❓ Interview Questions
Q: What is the Actions class in Selenium?
A: Actions class is used to perform advanced mouse and keyboard actions like click, double click, drag and drop, and hover.
Q: Which method performs right click in Selenium?
A: contextClick()
🎥 Watch the Complete Tutorial
👉 Watch on YouTube: Click Using Action Class in Selenium WebDriver
🎓 Key Takeaways
- Actions class performs advanced user interactions
- click() is used when normal click does not work
- doubleClick() performs double click action
- contextClick() performs right click
- dragAndDrop() moves element from source to target
🚀 Created with ❤️ by Bhau Automation