Introduction
Some web applications perform special actions only when the user double-clicks an element. Unlike a normal click, a double click consists of two rapid left mouse clicks on the same element.
Double-click functionality is commonly used in file managers, desktop-style web applications, image editors, dashboards, and custom UI components.
Selenium performs double-click operations using the ActionChains class and its double_click() method.
In this tutorial, you’ll learn how to automate double-click actions using Selenium with Python, along with practical examples, real-world scenarios, common mistakes, and best practices.
What is Double Click?
A Double Click is the action of pressing the left mouse button twice quickly on the same element.
Example:
User Double Clicks
│
▼
Target Element
│
▼
Special Action Occurs
Many applications assign different functionality to a double click than to a single click.
Why Automate Double Click?
Double-click automation helps you:
Test desktop-style web applications.
Verify custom UI interactions.
Test image editors.
Validate interactive dashboards.
Automate advanced mouse actions.
How Selenium Performs Double Click
Selenium uses the ActionChains class.
The most commonly used method is:
ActionChains(driver)\
.double_click(element)\
.perform()
This simulates two rapid left mouse clicks on the specified element.
Example
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
# Topic: 33. Actions Class - Double Click
# Practice site: https://www.testmuai.com/selenium-playground/
# Run: pytest -s 33_examples/test_04_double_click.py
#
# double_click sends two quick clicks to the same element. This example creates
# a small button and stores the result in a data attribute.
def test_double_click_button:
driver = webdriver.Chrome()
try:
driver.get("https://www.testmuai.com/selenium-playground/")
driver.execute_script(
"""
const button = document.createElement('button');
button.id = 'double-click-button';
button.textContent = 'Double click me';
button.addEventListener('dblclick', () => button.dataset.doubleClicked = 'yes');
document.body.appendChild(button);
"""
)
button = driver.find_element(By.ID, "double-click-button")
ActionChains(driver).double_click(button).perform()
assert button.get_attribute("data-double-clicked") == "yes"
finally:
driver.quit()
Understanding the Code
Import Required Libraries
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
These modules are required to launch the browser, locate web elements, and perform advanced mouse actions.
Create a Chrome Browser Instance
driver = webdriver.Chrome()
Starts a new Chrome browser session.
Open the Practice Website
driver.get("https://www.testmuai.com/selenium-playground/")
Navigates to the Selenium Playground website.
Create the Double-Click Button
driver.execute_script(
"""
...
"""
)
This JavaScript dynamically creates a button with the text “Double click me”.
It also registers a dblclick event listener that sets the custom attribute data-double-clicked="yes" whenever the button is double-clicked.
Locate the Button
button = driver.find_element(
By.ID,
"double-click-button"
)
Locates the dynamically created button.
Perform the Double Click
ActionChains(driver)\
.double_click(button)\
.perform()
Performs two rapid left mouse clicks on the button.
This triggers the JavaScript dblclick event attached to the button.
Verify the Double Click
assert button.get_attribute(
"data-double-clicked"
) == "yes"
Checks that the custom attribute was updated after the double-click operation.
If the attribute is not "yes", the test fails.
Close the Browser
driver.quit()
Closes the browser and ends the WebDriver session.
Practical Example
Suppose an online file manager opens a folder only when the user double-clicks it.
The automation script:
Opens the file manager.
Double-clicks a folder.
Verifies that the folder opens successfully.
Automation Testing Example
Consider a dashboard application where double-clicking a chart opens a detailed analytics view.
The automation script:
Opens the dashboard.
Double-clicks the chart.
Verifies that the detailed report is displayed.
Real-World Example
Double-click functionality is commonly used in:
File management systems
Desktop-style web applications
Dashboard widgets
Image editors
Online IDEs
Graphic design tools
Enterprise applications
Examples include opening folders, editing items, expanding reports, launching dialogs, and accessing detailed information.
Advantages of Double Click Automation
Tests advanced mouse interactions.
Simulates real user behavior.
Verifies custom UI functionality.
Supports desktop-style web applications.
Improves automation coverage.
Common Mistakes Beginners Make
Using click() Instead of double_click()
A normal click performs only one mouse click.
Use double_click() when the application expects two rapid clicks.
Forgetting to Call perform()
Without perform(), the ActionChain is created but never executed.
Assuming Every Double Click Behaves the Same
Different applications may trigger different events or behaviors after a double click.
Always verify the application’s expected response.
Not Verifying the Result
Always confirm that the double-click action produced the expected outcome.
Best Practices
Use
ActionChainsfor double-click interactions.Always call
perform()to execute the action.Verify the expected result after the double click.
Use Explicit Waits if the UI updates dynamically.
Keep double-click automation simple and readable.
Conclusion
Double-click is an important advanced mouse interaction used by many modern web applications. Selenium’s ActionChains class provides the double_click() method to simulate this behavior accurately. Understanding double-click automation is essential for testing desktop-style interfaces, dashboards, file managers, and interactive web applications.
Frequently Asked Questions (FAQs)
What is a Double Click?
A double click is the action of pressing the left mouse button twice rapidly on the same element.
Which Selenium class performs a double click?
The ActionChains class is used to perform double-click operations.
Which method performs the double click?
Use:
double_click(element)
to perform a double-click on an element.
Why is perform() required?
perform() executes the actions that have been added to the ActionChain.
Without it, the double-click action will not occur.
Where is double-click commonly used?
Double-click is commonly used in file managers, dashboards, online IDEs, image editors, desktop-style web applications, and enterprise software.
Key Takeaways
Double click consists of two rapid left mouse clicks.
Selenium performs double-click actions using
ActionChains.Use
double_click()to simulate a double click.Always call
perform()to execute the action.Verify that the application responds correctly after the double click.
Double-click automation is an essential Selenium skill for testing advanced interactive web applications.
