本文介绍了无法弄清楚python selenium webdriver move_to_element功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了许多示例以及ActionChains的源代码,似乎正在将其他示例中建议的代码用于悬停功能,但仍然无法克服此异常.代码如下:

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

,唯一的例外是:

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'

起初,我认为它不起作用,因为元素上没有id属性,但是我确认情况并非如此(find_element_by_xpath确实返回了正确的元素,并且为其分配了某种{unique id}) .我的Python技能很基础,但是我需要调整正在使用的测试脚本.我确定我只是不理解此错误.

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.

感谢您的帮助!

推荐答案

ActionChains的第一个参数是用于控制浏览器的驱动程序实例,在本例中为browser.请尝试以下操作:

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

这篇关于无法弄清楚python selenium webdriver move_to_element功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:14