selenium-ActionChains类的使用,鼠标基本事件

引入ActionChains模块

from selenium.webdriver.common.action_chains import ActionChains

ActionChains类提供的鼠标事件方法

perform()执行所有ActionChains存储的事件
context_click()右击
double-click()双击
drag_and_drop()拖动
move_to_element()悬停
click_and_hold()在一个元素上按下鼠标左键并保持
创建ActionChains对象
#用driver
Action = ActionChains(driver)
右击事件
element =driver.find_element_by_xpath('//*[@id="su"]')
Action.move_to_element(element).context_click().perform()

move_to_element定位到搜索按钮上,context_click()右击,
perform()提交之前的操作

效果截不下来,就算了

双击
element =driver.find_element_by_xpath('//*[@id="su"]')
Action.move_to_element(element).double_click().perform()

一般web测试用的不多,知道用法就好了

拖动
first_element = driver.find_element_by_xpath('某个元素的xpath')
two_element = dirver.find_element_by_xpath('第二个元素的xpath')
Action.drag_to_drop(first_element,two_element).perform()
按住
Action.move_to_element(element).click_and_hold().perform()

鼠标常用事件就这么多了,下期讲键盘操作。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值