【元素操作】鼠标 -ActionChains

actionchains是selenium里面专门处理鼠标相关的操作如:鼠标移动,鼠标按钮

ActionChains 的对象生成操作队列,在没有执行提交 perform() 之前,所有操作只是暂存于队列中,不会实际在页面上操作,需要执行 perform() 时才会实际执行操作

鼠标移动

python 复制代码
    #定位元素
    please_select = driver.find_element(By.CSS_SELECTOR,'.app-address-title')
    #定义动作-鼠标移动
    action =ActionChains(driver)
    action.**move_to_element**(please_select).perform() #注意,必须执行perform方法

单击并且释放

右键点击

click() 点击指定元素,如果没有指定元素,则点击当前鼠标所在位置

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).click(e).perform()

双击

double_click(on_element=None) 双击元素,如果没有指定元素则在当前鼠标位置双击

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).double_click(e).perform()

移动到某元素中心的偏移量的位置

move_to_element_with_offset(to_element, xoffset, yoffset) 将鼠标移动到基于元素的偏移量,偏移量基于鼠标左上角的坐标点

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).move_to_element_with_offset(e, 100, 100).perform()

元素点击

python 复制代码
e = driver.find_element_by_id('su')
ActionChains(driver).context_click(e).perform()

元素输入

python 复制代码
driver.find_element(By.XPATH,'//label[@for="name"]/following-sibling::div//input').send_keys('测试')

元素内容清除

python 复制代码
driver.find_element(By.XPATH,'//label[@for="name"]/following-sibling::div//input').clear()

元素是否显示

相关推荐
好家伙VCC2 小时前
**神经编码新视角:用Python实现生物启发的神经信号压缩与解码算法**在人工智能飞速发展的今天
java·人工智能·python·算法
踏着七彩祥云的小丑8 小时前
pytest——Mark标记
开发语言·python·pytest
不爱吃炸鸡柳9 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
Dxy123931021610 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert
运维行者_11 小时前
OpManager MSP NetFlow Analyzer集成解决方案,应对多客户端网络流量监控挑战
大数据·运维·服务器·网络·数据库·自动化·运维开发
SiYuanFeng11 小时前
Colab复现 NanoChat:从 Tokenizer(CPU)、Base Train(CPU) 到 SFT(GPU) 的完整踩坑实录
python·colab
炸炸鱼.12 小时前
Python 操作 MySQL 数据库
android·数据库·python·adb
_深海凉_13 小时前
LeetCode热题100-颜色分类
python·算法·leetcode
AC赳赳老秦13 小时前
OpenClaw email技能:批量发送邮件、自动回复,高效处理工作邮件
运维·人工智能·python·django·自动化·deepseek·openclaw
大强同学13 小时前
Obsidian 日记:从模板到 Dataview 自动化
运维·自动化