我正在尝试在可见元素上进行鼠标悬停操作,然后单击隐藏的子菜单项。 move_to_element()
似乎不适用于 ChromeDriver。但是,运行代码没有异常,只是操作没有发生。
我也尝试过 sleep()
在操作和 webDriverWait
--- 之间显示运行代码超时。我将 chrome 56.0 与 python 2.7 和 selenium 3.0.2 一起使用。
以下是 HTML 代码
<a class="dropdown-toggle" href="about-us.html" data-toggle="dropdown" role="button" aria-expanded="false">
About
<i class="caret"></i>
</a>
<li>
<a href="about.html">Introduction</a>
</li>
以下是我的测试用例的一部分
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
mainmenu = driver.find_element_by_xpath("path_to_about_element")
submenu =driver.find_element_by_xpath("path_to_introduction_element")
action=ActionChains(driver)
action.move_to_element(mainmenu)
action.move_to_element(submenu)
action.click().perform()
原文由 renuka 发布,翻译遵循 CC BY-SA 4.0 许可协议
谢谢你们的帮助。我终于发现
moveToElement()
如果物理光标在浏览器窗口内则不起作用。这是 ChromeDriver 的一个已知问题。https://bugs.chromium.org/p/chromedriver/issues/detail?id=605