【元素操作】鼠标 -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()

元素是否显示

相关推荐
aqi0033 分钟前
15天学会AI应用开发(十四)搭建LangChain的开发环境
人工智能·python·大模型·ai编程·ai应用
2601_954706491 小时前
算力上云革新移动终端:ARM 虚拟化云手机底层原理、API 自动化实战与 2026 选型全解
arm开发·智能手机·自动化
想会飞的蒲公英1 小时前
词袋模型与 CountVectorizer:文本也可以做特征表
人工智能·python·机器学习
LadenKiller1 小时前
近期量化工具推荐,问题位置比功能清单更重要
人工智能·python
Hesionberger1 小时前
LeetCode406:重建身高队列精髓解析
开发语言·数据结构·python·算法·leetcode
郭老二1 小时前
【Python】基本语法:线程、锁
python
小白学大数据2 小时前
企业内网场景下 Python 自定义 CA 证书信任链的正确配置方法
开发语言·网络·python·信任链
海兰2 小时前
【Elasticsearch】工作流自动化评估
elasticsearch·自动化·jenkins
Java面试题总结2 小时前
使用 Python 在 Excel 中添加和自定义文本框
开发语言·python·excel