- 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 can I perform mouse hover action in Selenium-Python?
We can perform mouseover action in Selenium webdriver in Python by using the ActionChains class. We have to create an object of this class and then apply suitable methods on it.
In order to move the mouse to an element, we shall use the move_to_element method and pass the element locator as a parameter. Then apply the perform method to actually perform this action. After hovering on the element, we can apply click action on it with the help of the click method.
a = ActionChains(driver) m= driver.find_element_by_link_text("Enabled") a.move_to_element(m).perform()
Let us try to hover on the element Enabled as shown on the below page −
from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://the-internet.herokuapp.com/jqueryui/menu#") #object of ActionChains a = ActionChains(driver) #identify element m = driver.find_element_by_link_text("Enabled") #hover over element a.move_to_element(m).perform() #identify sub menu element n = driver.find_element_by_link_text("Back to JQuery UI") # hover over element and click a.move_to_element(n).click().perform() print("Page title: " + driver.title) #close browser driver.close()
- How to perform scrolling action on page in Selenium?
- How to perform mouse movement to an element in Selenium with python?
- How to perform releasing a mouse on an element in Selenium with python?
- How to perform mouseover action on an element in Selenium?
- Select item from sub-menu of a menu using mouse over action in Selenium
- How can I delete an element in Selenium using Python?
- How can I manually set proxy settings in Python Selenium?
- How can I scroll a web page using selenium webdriver in python?
- How can I parse a website using Selenium and Beautifulsoup in python?
- How can I get Webdriver Session ID in Selenium?
- How can I show and hide div on mouse click using jQuery?
- Human-like mouse movements with Selenium.
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to do drag and drop action in Selenium?