06-鼠标事件-ActionChains类
发布日期:2021-05-07 13:04:37 浏览次数:17 分类:精选文章

本文共 1105 字,大约阅读时间需要 3 分钟。

目录


1. 常用方法

  • perform(): 执行所有 ActionChains 中存储的行为
  • context_click(): 右键单击
  • double_click(): 双击鼠标左键
  • drag_and_drop(): 拖拽到某个元素然后松开
  • move_to_element(): 鼠标悬停
# -*-coding:utf-8一*-# @Time:2021/1/13# @Author: 大海from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsdriver = webdriver.Chrome()driver.get("https://www.baidu.com")# 隐式等待,后面介绍driver.implicitly_wait(10)# 鼠标悬停在搜索设置按钮上mouse = driver.find_element_by_link_text("设置")# ActionChains类需将驱动driver作为参数传入# perform() 执行move_to_element(mouse) 鼠标悬浮的动作ActionChains(driver).move_to_element(mouse).perform()

2. 其他方法

  • click(on_element=None) :单击鼠标左键
  • click_and_hold(on_element=None) :点击鼠标左键,不松开
  • drag_and_drop_by_offset(source, xoffset, yoffset) :拖拽到某个坐标然后松开
  • key_down(value, element=None) :按下某个键盘上的键
  • key_up(value, element=None) :松开某个键
  • move_by_offset(xoffset, yoffset) :鼠标从当前位置移动到某个坐标
  • move_to_element(to_element) :鼠标移动到某个元素
  • move_to_element_with_offset(to_element, xoffset, yoffset) :移动到距某个元素(左上角坐标)多少距离的位置
  • release(on_element=None) :在某个元素位置松开鼠标左键
  • send_keys(*keys_to_send) :发送某个键到当前焦点的元素
  • send_keys_to_element(element, *keys_to_send) :发送某个键到指定元素
上一篇:07-键盘事件-Keys类
下一篇:05-Element对象常用方法

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月14日 08时25分50秒