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

元素是否显示

相关推荐
志栋智能5 小时前
超自动化巡检如何生成“有灵魂”的运维报告?
大数据·运维·人工智能·架构·自动化
湘美书院--湘美谈教育5 小时前
湘美书院随笔:AI时代的生活经济学
大数据·人工智能·安全·自动化·生活
Splashtop高性能远程控制软件5 小时前
微软 2026 年 9 月补丁星期二技术分析:974 个漏洞的分级修复优先级清单
运维·安全·自动化·远程工作·splashtop
wuhuhuan5 小时前
Case Generator 平台升级
python·测试工具·自动化
RobinDevNotes5 小时前
用 Profile 揪出大模型训练性能瓶颈
python·性能优化
李航19835 小时前
用 DeepDraw 几何引擎开发建筑设计软件(六):创建画线工具
python·软件构建
AI 编程助手GPT5 小时前
Python 备份 SQLite:为什么复制了 .db,恢复后还是少数据?
人工智能·python·ai·chatgpt
狗都不学爬虫_6 小时前
AI逆向 - 天御无感点击验证(补+纯)
爬虫·python·网络爬虫
机核研创社6 小时前
HN 慧拿 HN-06 全自动上橡筋机|圆筒扩张结构与三针五线绷缝原理
人工智能·自动化
529宝宝起名网6 小时前
用 Python 开发历史名字查询与起名灵感工具:从古籍人物数据库到名字文化故事生成
开发语言·前端·python