Double click is used to perform a quick two-click action on a web element. It helps test features that respond to double clicks, like opening files or editing text.
0
0
Double click in Selenium Python
Introduction
When testing a button that opens a menu on double click.
When verifying that double clicking a list item selects it.
When checking if double click triggers a special action on an image.
When automating text editing that requires double click to select a word.
Syntax
Selenium Python
from selenium.webdriver import ActionChains actions = ActionChains(driver) actions.double_click(element).perform()
You need to import ActionChains from Selenium.
Always call perform() to execute the double click action.
Examples
Double clicks on a button element.
Selenium Python
actions = ActionChains(driver) actions.double_click(button).perform()
Double clicks on a text field to select text or trigger editing.
Selenium Python
actions = ActionChains(driver) actions.double_click(text_field).perform()
Sample Program
This script opens a jQuery demo page where double clicking a box changes its color. It switches to the demo frame, double clicks the box, waits 2 seconds, then prints the new background color.
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver import ActionChains import time # Setup driver (make sure chromedriver is in PATH) driver = webdriver.Chrome() driver.get('https://api.jquery.com/dblclick/') # Switch to the frame containing the demo frame = driver.find_element(By.CSS_SELECTOR, 'iframe.demo-frame') driver.switch_to.frame(frame) # Find the box to double click box = driver.find_element(By.CSS_SELECTOR, 'div#target') # Create action chain and double click actions = ActionChains(driver) actions.double_click(box).perform() # Wait to see the color change time.sleep(2) # Check if color changed to rgb(255, 255, 0) (yellow) color = box.value_of_css_property('background-color') print(f'Background color after double click: {color}') # Cleanup driver.quit()
OutputSuccess
Important Notes
Make sure the element is visible and interactable before double clicking.
Use explicit waits if the element loads dynamically.
Double click may behave differently on some browsers; test accordingly.
Summary
Double click simulates two quick clicks on an element.
Use ActionChains and call double_click(element).perform().
Useful for testing UI features triggered by double clicks.