- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform releasing a mouse on an element in Selenium with python?
We can perform mouse release from an element in Selenium with the help of Action Chains class. These classes are generally used for automating interactions like context menu click, mouse button actions, key press and mouse movements.
These types of actions are mainly common in complex scenarios like drag and drop and hovering over an element on the page. The methods of the Action Chains class are utilized by advanced scripts. We can manipulate DOM with the help of Action Chains in Selenium.
The action chain object implements the ActionChains in the form of a queue and then executes the perform() method. On calling the method perform(), all the actions on action chains will be performed.
The method of creating an Action Chain object is listed below −
First we need to import the Action Chain class and then the driver will be passed as an argument to it.
Now all the operations of action chains can be done with the help of this object.
Syntax for creating an object of Action Chains −
from selenium import webdriver
# import Action chains from selenium.webdriver import ActionChains # create webdriver object driver = webdriver.Firefox() # create action chain object action = ActionChains(driver)
After creating an object of Action Chains, we can perform numerous operations one by one like a chain which is queued.
release() – This method performs releasing a held mouse button on an element.
Where args is the element from where the mouse is released up. If the arguments are omitted, it shall release the present position of mouse.
#element source = driver.find_element_by_id("name") #action chain object action = ActionChains(driver) # move to element operation action.click(source) # release the mouse up action.release(source) # perform the action action.perform()
Code Implementation for releasing a mouse operation.
from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/about/about_careers.htm") #to refresh the browser driver.refresh() # identifying the source element source= driver.find_element_by_xpath("//*[text()='Company']"); # action chain object creation action = ActionChains(driver) # click the element action.click(source) # release the element action.release(source) # perform the action action.perform() #to close the browser driver.close()
- How to perform mouse movement to an element in Selenium with python?
- How to perform right click on an element in Selenium with python?
- How to perform double click on an element in Selenium with python?
- How to perform right click on an element with Actions in Selenium?
- How to perform mouseover action on an element in Selenium?
- How to perform double click on an element in Selenium?
- How can I perform mouse hover action in Selenium-Python?
- How to perform scrolling action on page in Selenium?
- How to perform back and refresh in a browser in Selenium with python?
- Flip an image on mouse over with CSS
- Human-like mouse movements with Selenium.
- How to click on a link in Selenium with python?
- How to perform drag and drop operation in Selenium with python?
- How to find the status of an element in a page in Selenium with python?