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

元素是否显示

相关推荐
玄同7651 小时前
从 0 到 1:用 Python 开发 MCP 工具,让 AI 智能体拥有 “超能力”
开发语言·人工智能·python·agent·ai编程·mcp·trae
小瑞瑞acd1 小时前
【小瑞瑞精讲】卷积神经网络(CNN):从入门到精通,计算机如何“看”懂世界?
人工智能·python·深度学习·神经网络·机器学习
火车叼位1 小时前
也许你不需要创建.venv, 此规范使python脚本自备依赖
python
火车叼位2 小时前
脚本伪装:让 Python 与 Node.js 像原生 Shell 命令一样运行
运维·javascript·python
L543414462 小时前
告别代码堆砌匠厂架构让你的系统吞吐量翻倍提升
大数据·人工智能·架构·自动化·rpa
孤狼warrior2 小时前
YOLO目标检测 一千字解析yolo最初的摸样 模型下载,数据集构建及模型训练代码
人工智能·python·深度学习·算法·yolo·目标检测·目标跟踪
Katecat996632 小时前
YOLO11分割算法实现甲状腺超声病灶自动检测与定位_DWR方法应用
python
玩大数据的龙威2 小时前
农经权二轮延包—各种地块示意图
python·arcgis
ZH15455891312 小时前
Flutter for OpenHarmony Python学习助手实战:数据库操作与管理的实现
python·学习·flutter
码农阿豪3 小时前
多服务器批量指令管理:从Xshell到自动化运维
运维·服务器·自动化