Reputation: 13
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()
Upvotes: 1
Views: 5316
Reputation: 52665
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()
Upvotes: 1
Reputation: 13
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']")))
Upvotes: 0