selenium 鼠标悬停事件

1.鼠标不仅仅可以点击(click),鼠标还有其它的操作,如:鼠标悬停在某个元素上,鼠标右击,鼠标按住某个按钮拖动;
2.鼠标事件需要先导入模块:
from selenium.webdriver.common.action_chains import ActionChains

perform() 执行所有 ActionChains 中的行为

move_to_element() 鼠标悬停

3.这里以百度页面设置按钮为例

#coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
#鼠标悬停在搜索设置按钮上
mouse = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(mouse).perform()

4.除了常用的鼠标悬停事件外,还有

右击鼠标:context_click()
双击鼠标:double_click()

依葫芦画瓢,替换上面案例中对应的鼠标事件就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值