gpt4 book ai didi

python - 无法弄清楚 python selenium webdriver move_to_element 功能

转载 作者:太空狗 更新时间:2023-10-30 02:12:30 27 4
gpt4 key购买 nike

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

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

异常(exception)情况是:

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

感谢您的帮助!

最佳答案

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

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

关于python - 无法弄清楚 python selenium webdriver move_to_element 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15281887/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com