8

I'm running into an issue with my Selenium script on Python. In the javascript web application that I'm interacting with, an element I need to click doesn't exist until I hover over it. I've looked and found various answers on how to hover, but the sequence needs to include the clicking of a new element during the hover event. Here is the code I am currently working with. The element is renamed from add to add1 when a hover occurs, once add1 exists; I should be able to click/send.keys to execute said element.

...
driver = webdriver.Firefox()
from selenium.webdriver.common.action_chains import ActionChains
...
add = driver.find_element_by_css_selector('input.add')
Hover = ActionChains(driver).move_to_element(add)
Hover.perform()
SearchButton = driver.find_element_by_css_selector('input.add1')
SearchButton.click()

I'm new with Python and with programming in general, but I can't figure out how to sequence this correctly.

Any help would be greatly appreciated.

vbiqvitovs
  • 1,533
  • 3
  • 12
  • 17

2 Answers2

21

Following had worked for me, please give a try:

add = driver.find_element_by_css_selector('input.add')
SearchButton = driver.find_element_by_css_selector('input.add1')

Hover = ActionChains(driver).move_to_element(add).move_to_element(SearchButton)
Hover.click().build().perform()

I'm not sure about above Python code. But you can use above logic.

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • 1
    Be aware about these error: 'ActionChains' object has no attribute 'build' I removed build of your solution in my code. But thanks by the rest of answer, it was very useful for me. – Zini Jun 30 '15 at 17:10
1

here another useful link How to mouseover in python Webdriver

@TDHM you should mention this below line to make it works

from selenium.webdriver.common.action_chains import ActionChains

thank you

Community
  • 1
  • 1
sohom
  • 577
  • 4
  • 7