有没有一种方法可以使用Selenium和Python绑定执行鼠标悬停(悬停在元素上)? [英] Is there a way to perform a mouseover (hover over an element) using Selenium and Python bindings?

查看:230
本文介绍了有没有一种方法可以使用Selenium和Python绑定执行鼠标悬停(悬停在元素上)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处读,显然以前是<使用hover方法的c0>类.但是,它是专门为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.

不能使用hover "noreferrer"> 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆