1

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()

2
  • You have a syntax error at actions =Action Chains(driver). Please show the error message. Commented Jan 6, 2017 at 10:28
  • corrected but still getting same error at perform() function. after comment out last line it properly complied but for performing mouse over operation I have to mention perform() method, might be problem bcz of windows10 Commented Jan 6, 2017 at 11:25

2 Answers 2

1

You don't need to perform both actions in a chain. Try the following code:

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

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

actions =chains(driver)
val1 = driver.find_element_by_xpath('//li[a[@title="Men"]]')
actions.move_to_element(val1).perform()
val2 = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//a[span[text()="Shirts"]]')))
val2.click()
Sign up to request clarification or add additional context in comments.

3 Comments

error # actions.move_to_element(menu) val1 = driver.find_element_by_xpath('//li[a[@title="Men"]]') > actions.move_to_element(val1).perform() TestScripts\test_sample_mouse_over.py:20: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Hey :) What is that actions.move_to_element(menu) !? There is no such line in my code...as well as in your initial code
Did you get exception like Message: POST /session/... did not match a known command with Firefox?
0

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']")))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.