mouseover doesn't work when I try to automate using selenium

Viewed 71

I'm trying automating a website and I'm trying to access a menu > submenu and perform a click on the item in submenu. After a lot of search I learned that mouseover is a better option for me as the submenu only appear if I hover the mouse on the menu. I have tried many instances but the mouse just won't hover on the main menu and to submenu. The code is:

policymngmt = driver.find_element_by_xpath('/html/body/app-root/div/div/main/site-header/div[1]/div[1]/div[2]/div/div/div/div/div[2]/ul/li[2]/a')
issuance = driver.find_element_by_xpath('/html/body/app-root/div/div/main/site-header/div[3]/div/div[1]/nx-link/a')
        
actions = ActionChains(driver)
actions.move_to_element(policymngmt).move_to_element(issuance).click().perform()
1 Answers

Try the below

actions = ActionChains(driver)

policymngmt = driver.find_element_by_xpath("xpath")

hover= ActionChains(driver).move_to_element(policymngmt)
hover.perform()


WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html/body/app-root/div/div/main/site-header/div[3]/div/div[1]/nx-link/a"))).click()

Imports

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
Related