小编tha*_*irl的帖子

python selenium:move_to_element() 不起作用

我正在尝试将鼠标悬停在可见元素上,然后单击隐藏的子菜单项。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> 
Run Code Online (Sandbox Code Playgroud)

以下是我的测试用例的一部分

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()
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-chromedriver

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

selenium ×1

selenium-chromedriver ×1