有没有办法使用 Selenium 和 Python 绑定执行鼠标悬停(悬停在元素上)? [英] Is there a way to perform a mouseover (hover over an element) using Selenium and Python bindings?
问题描述
阅读此处,显然曾经有一个<带有 hover
方法的 code>RenderedWebElement 类.然而,它是专为 Java 制作的(我已经搜索了 Python 绑定文档,但无济于事)并且此后已被 Java 弃用.
Reading here, there apparently used to be a RenderedWebElement
class with a hover
method. It, however, was exclusively made for Java (I have searched the Python bindings documentation to no avail) and has since been deprecated for Java.
无法使用 action_chains
也不使用 WebElement
对象.
A hover
can't be performed using action_chains
nor by using a WebElement
object either.
有关如何为 Python 执行此操作的任何想法?我一直在这里但它使用RenderedWebElement
并因此没有太大帮助.
Any ideas as to how to do this for Python? I have been here but it uses RenderedWebElement
and hence doesn't help too much.
我正在使用:Python 2.7、Windows Vista、Selenium 2、Python 绑定
selenium.selenium.selenium
对象有一个方法 mouse_over
但我无法找到一种方法来创建一个实例已经运行了独立服务器.
There is a method mouse_over
for a selenium.selenium.selenium
object but I cannot figure a way to create an instance without having the stand-alone server running already.
编辑请仔细阅读标记为答案的回复的评论,以防万一您像我一样有误解!
EDIT Please go through the comments of the reply marked as answer just in-case you have misconceptions like I did !
推荐答案
要进行悬停,您需要使用 move_to_element
方法.
To do a hover you need to use the move_to_element
method.
这是一个例子
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
firefox = webdriver.Firefox()
firefox.get('http://foo.bar')
element_to_hover_over = firefox.find_element_by_id("baz")
hover = ActionChains(firefox).move_to_element(element_to_hover_over)
hover.perform()
这篇关于有没有办法使用 Selenium 和 Python 绑定执行鼠标悬停(悬停在元素上)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!