mak mak - 2 months ago 11
Python Question

mouse over operation in python selenium

I am trying to perform mouse over operation in

python
selenium
binding, but I am getting error while using
ActionChains.perform()


I have tried this

def test_mouse_over():

driver =webdriver.Firefox()
driver.get("https://www.flipkart.com/")

actions = ActionChains(driver)
val1 = driver.find_element_by_xpath('//span[text()="Men"]')
actions.move_to_element(val1)
val2 = driver.find_element_by_xpath('//span[text()="Shirts"]')
actions.click(val2)
actions.perform()


I am getting error at last line
actions.perform()

mak mak
Answer Source

correct solution

def test_mouse_over():
    """mouse over operation FLIPKART.COM"""
    driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe")  # in chrome this code is working

    # driver = webdriver.Firefox() # in forefox this code is not working

    driver.get("https://www.flipkart.com/")
    driver.implicitly_wait(20)
    driver.maximize_window()

    menu = driver.find_element_by_xpath("//span[text()='Women']")
    hidden_submenu = driver.find_element(By.XPATH, "//span[text()='Flats']")

    actions = ActionChains(driver)

    actions.move_to_element(menu).click().perform()

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Flats']")))
    try:
        actions.click(hidden_submenu).perform()
    except:
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Flats']")))