python调用鼠标驱动,有没有一种方法可以使用Selenium和Python绑定执行鼠标悬停(悬停在元素上)?...

这篇博客讨论了如何在Python中使用Selenium库进行网页元素的悬停操作。原来的方法,如RenderedWebElement的hover已被弃用。作者发现无法通过action_chains或直接使用WebElement对象来实现hover。解决方案是使用ActionChains的move_to_element方法。示例代码展示了如何定位元素并执行悬停。
摘要由CSDN通过智能技术生成

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.

A hover can't be performed using action_chains nor by using a WebElement object either.

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.

I am using: Python 2.7, Windows Vista, Selenium 2, Python Bindings

EDIT: 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 !

解决方案

To do a hover you need to use the move_to_element method.

Here is an example

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值