【问题标题】:Cannot figure out python selenium webdriver move_to_element functionality无法弄清楚 python selenium webdriver move_to_element 功能
【发布时间】:2013-02-23 06:47:12
【问题描述】:

我查看了一些示例以及 ActionChains 的源代码,似乎正在使用其他示例中建议的代码来实现悬停功能,但我仍然无法克服这个异常。代码如下:

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 技能非常初级,但我需要调整我正在编写的测试脚本。我确定我只是不明白这个错误。

感谢您的帮助!

【问题讨论】:

    标签: python selenium webdriver mouseover


    【解决方案1】:

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

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

    【讨论】:

    • 是的,我太傻了。 :-) 好收获!
    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多