- Selenium Webdriver Tutorial
- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
Selenium Webdriver - Double Click
Selenium can perform mouse movements, key press, hovering on an element, double click, drag and drop actions, and so on with the help of the ActionsChains class. The method double_click performs double-click on an element.
The syntax for using the double click is as follows:
double_click(e=None)
Here, e is the element to be double-clicked. If None is mentioned, the click is performed on the present mouse position. We have to add the statement from selenium.webdriver import ActionChains to work with the ActionChains class.
Let us perform the double click on the below element −
In the above image, it is seen that on double clicking the Double Click me! button, an alert box gets generated.
Code Implementation
The code implementation for using the double click is as follows −
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.alert import Alert driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #implicit wait time driver.implicitly_wait(5) #url launch driver.get("http://www.uitestpractice.com/Students/Actions") #identify element s = driver.find_element_by_name("dblClick") #object of ActionChains a = ActionChains(driver) #right click then perform a.double_click(s).perform() #switch to alert alrt = Alert(driver) # get alert text print(alrt.text) #accept alert alrt.accept() #driver quit driver.quit()
Output
The output shows the message - Process with exit code 0 meaning that the above Python code executed successfully. Also, the Alert text - Double Clicked! gets printed in the console. The Alert got generated by double clicking the Double Click me! button.
To Continue Learning Please Login
Login with Google