selenium鼠标操作方法

1.0 selenium新版本封装驱动

bash 复制代码
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import ChromiumOptions
from selenium.webdriver.chrome.service import Service


def get_chrome_driver(driver_path):
    chrome_options = ChromiumOptions()
    chrome_options.add_argument("driver_path='./chromedriver.exe'")
    # chrome_options.add_argument("--headless")
    chrome_options.add_argument("--start-maximized")
    chrome_options.add_argument("user-agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'")
    chrome_options.add_argument('--start-maximized') # 最大化运行(全屏窗口),不设置,取元素会报错

    chrome_options.add_argument('--disable-infobars') # 禁用浏览器正在被自动化程序控制的提示

    chrome_service =  Service(driver_path)

    chrome_driver = Chrome(options=chrome_options,service=chrome_service)
    return chrome_driver

2.0 鼠标操作常用的方法

bash 复制代码
ActionChains方法列表
click(on_element=None) ------单击鼠标左键
click_and_hold(on_element=None) ------点击鼠标左键,不松开
context_click(on_element=None) ------点击鼠标右键
double_click(on_element=None) ------双击鼠标左键
drag_and_drop(source, target) ------拖拽到某个元素然后松开
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) ------移动到距某个元素(左上角坐标)多少距离的位置
perform() ------执行链中的所有动作
release(on_element=None) ------在某个元素位置松开鼠标左键
send_keys(*keys_to_send) ------发送某个键到当前焦点的元素
send_keys_to_element(element, *keys_to_send) ------发送某个键到指定元素 
相关推荐
Saniffer_SH2 小时前
【每日一题】PCIe链路协商的时候进入Polling compliance如何排错?
服务器·人工智能·驱动开发·嵌入式硬件·测试工具·fpga开发·自动化
张永清-老清3 小时前
每周读书与学习->Jmeter中如何使用Bean Shell脚本(二)Bean Shell的基础语法之变量与数据类型
学习·测试工具·jmeter·压力测试·性能调优·jmeter性能测试·性能分析
0和1的舞者15 小时前
高并发论坛系统:单元测试 + 接口自动化 + 性能测试 + CI/CD 全链路测试报告
java·测试开发·测试工具·jmeter·pytest·测试·测试报告
小杨的博客18 小时前
Java + Selenium实现浏览器打印功能
java·selenium
敷衍一下X18 小时前
Selenium元素定位
python·selenium·测试工具
汽车仪器仪表相关领域19 小时前
SSI-4 PLUS 简易传感器接口:多场景采集 “即插即用” 的终极解决方案
功能测试·测试工具·单元测试·压力测试·可用性测试·模块测试·安全性测试
派葛穆20 小时前
Unity-鼠标悬停改变图像位置
unity·计算机外设·交互
Saniffer_SH1 天前
【高清视频】4小时带你了解Saniffer公司针对PCIe Gen6测试的最新白皮书15.X
网络·人工智能·驱动开发·嵌入式硬件·测试工具·计算机外设·压力测试
怪侠_岭南一只猿1 天前
爬虫阶段三实战练习题二:使用 Selenium 模拟爬取拉勾网职位表
css·爬虫·python·selenium·html