Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot figure out python selenium webdriver move_to_element functionality

I looked at number of examples as well as source code for ActionChains and seemingly am using the code suggested in other examples for hover functionality, but still I cannot get over this exception. The code is as follows:

menu = browser.find_element_by_xpath("//nav/ul/li/a[@href='#'][.='Profile']")
hover = ActionChains(webdriver).move_to_element(menu)
hover.perform()

and the exception is:

Traceback (most recent call last):
File "./test.py", line 56, in <module>
hov.perform()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py", line 44, in perform
action()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py", line 201, in <lambda>
self._driver.execute(Command.MOVE_TO, {'element': to_element.id}))
AttributeError: 'module' object has no attribute 'execute'

At first, I thought it was not working because there is no id attribute on the element, however I confirmed that is not the case (find_element_by_xpath does return correct element and there is some sort of {unique id} assigned to it). My Python skills are quite elementary, but I need to adapt the testing script I working on. I am sure I just don't understand this error.

Thanks for your help!

like image 273
user1762591 Avatar asked Feb 17 '23 06:02

user1762591


1 Answers

The first argument to ActionChains is the driver instance you use to control the browser, ie browser in this case. Try the following:

menu = browser.find_element_by_xpath("//nav/ul/li/a[@href='#'][.='Profile']")
hover = ActionChains(browser).move_to_element(menu)
hover.perform()
like image 197
TAS Avatar answered Feb 19 '23 20:02

TAS