How can I perform mouse hover action in Selenium-Python

0 votes
How can I perform mouse hover action in Selenium-Python?
Jul 23, 2019 in Selenium by Payal
17,321 views

1 answer to this question.

0 votes

Hey Payal, use the code snippet shown below to perform mouse hover in Python with Selenium:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
    
driver = webdriver.Firefox()
driver.get("https://www.edureka.co")

action = ActionChains(driver);

parent_level_menu = driver.find_element_by_id("tabscathome")
action.move_to_element(parent_level_menu).perform()

child_level_menu = driver.find_element_by_xpath("//a[contains(text(),'DevOps')]")
child_level_menu.click();

sleep(10)

driver.close()

For further understanding, you can refer to the Selenium Course.

answered Jul 24, 2019 by Abha
• 28,140 points
Did not work .

Try this for hover/mouseover in python web driver:

from selenium.webdriver.common.action_chains import ActionChains
def hover(self):
    wd = webdriver_connection.connection
    element = wd.find_element_by_link_text(self.locator)
    hov = ActionChains(wd).move_to_element(element)
    hov.perform()
I need to hover my mouse cursor to the hamburger menu of Amazon.com
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox(executable_path="")
driver.get("https://UrlToOpen") 
action = ActionChains(driver)
firstLevelMenu = driver.find_element_by_id("menu")
action.move_to_element(firstLevelMenu).perform()
secondLevelMenu = driver.find_element_by_xpath("//a[contains(text(),'menu1')]")
secondLevelMenu.click()

You could use this code snippet by just replacing the necessary urls and menu items.

Related Questions In Selenium

+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 28, 2018 in Selenium by nsv999
• 5,500 points
27,424 views
+1 vote
2 answers

How can I delete an element in Selenium using Python?

You can directly delete the node using ...READ MORE

answered Sep 14, 2019 in Selenium by tonystark
• 500 points
19,911 views
0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9, 2019 in Selenium by Anvi
• 14,150 points
915 views
0 votes
1 answer

How can I perform multiple selection of options in a dropdown using Select class in Selenium?

Hey Priyansh, you can select multiple options ...READ MORE

answered Jul 8, 2019 in Selenium by Anvi
• 14,150 points
3,247 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,150 points
15,887 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,775 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,188 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,265 views
0 votes
1 answer

How can I perform mouse hover to a web element with ruby and selenium webdriver?

Hi Siddhart, checkout the following script to ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 28,140 points
2,612 views
0 votes
1 answer

How can I manually set proxy settings in Python Selenium?

Hi Jyotsana, you can manually set proxy ...READ MORE

answered Jul 29, 2019 in Selenium by Abha
• 28,140 points
22,759 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP