Windows自动化1️⃣环境搭建WinAppDriver

对于技术选型:

我尝试了, pywinauto, WinAppDriver,CukeTest

担心CukeTest可能会收费, 尝试pywinauto,在元素点击,搜索时, 遇到不可用情况; WinAppDriver是微软家的,大厂开源, 就它了!

步骤一:安装WinAppDriver

进入WinAppDriver下载页面(https://github.com/Microsoft/WinAppDriver/releases),下载WinAppDriver安装程序。例如下载WinAppDriver v1.2.1

步骤二:开启开发人员模式

  1. WinAppDriver的运行需要开启开发人员模式,否则无法运行。依次进入计算机的设置>>更新和安全>>开发者选项,将【开发人员模式】打开

  2. 开启后,如果日志有乱码, 修改windows编码格式: 设置->区域->管理->更改系统区域设置: Beta版:使用Unicode提供全球语言支持

  3. 重启windows

**步骤三:**运行WinAppDriver.exe程序

进入WinAppDriver的安装路径,以管理身份运行WinAppDriver.exe程序。启动成功后会弹出一个命令行窗口,提示"Windows Application Driver listening for requests at: http://127.0.0.1:4723/"

WinAppDriver启动后默认会IP地址和端口号为127.0.0.1:4723上的请求,在使用时我们可以配置监听的IP地址和端口号

入WinAppDriver.exe所在路径下,执行命令WinAppDriver.exe 4727即可完成

元素识别工具

WinApp元素识别工具有很多,例如WinSpy、AccEvent、Inspect。最早的时候使用Inspect工具识别WinApp上的标题栏、菜单栏、工具栏、树视图及数据视图,但是随着技术的发展和人们的需求变化,微软推出了Accessibility Insights工具代替Inspect,在Inspect官网文档中也建议用户使用Accessibility Insights工具。
urllib3 版本出错, 安装1.26.2版本 pip install urllib3==1.26.2

软件地址:winsdksetup.exe

https://download.microsoft.com/download/2/6/f/26f7aa55-ef6f-4882-b19b-a1be0e7328fe/KIT_BUNDLE_WINDOWSSDK_MEDIACREATION/winsdksetup.exe

windows定位工具包:

https://codeload.github.com/blackrosezy/gui-inspect-tool/zip/refs/heads/master

微软定位工具包:

https://codeload.github.com/microsoft/WinAppDriver/zip/refs/heads/master

demo代码:

python 复制代码
import time
import pyautogui
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys  # 鼠标右键操作模拟
from selenium.webdriver import ActionChains  # 鼠标右键操作模拟

# 添加启动参数
desired_caps = {}
desired_caps['app'] = r"D:\\Users\\duxiaowei\\AppData\\Local\\Programs\\Hwork\\Hwork.exe"
# 客户端连接 Server,启动 Session 会话
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps)
time.sleep(3)


# driver.find_element(by=By.NAME, value="工作台").click()
# time.sleep(2)
#

driver.find_element(by=By.NAME, value="消息").click()
time.sleep(2)

# driver.find_element(by=By.NAME, value="群组").click()
# time.sleep(2)
# driver.find_element(by=By.NAME, value="Hwork测试群").click()
# time.sleep(2)

driver.find_element(by=By.NAME, value="搜索").click()
time.sleep(1)
相关推荐
豆沙沙包?6 小时前
C++~~~stack容器、queue容器、list容器(p45-P56)
c++·windows·list
专注API从业者7 小时前
告别人工盯品!借助 Open Claw 搭建电商商品自动化监控与数据分析系统(完整可运行源码)
大数据·运维·数据库·数据分析·自动化
weixin_403810137 小时前
AI智能体写安卓自动化脚本教程:Cursor/Trae+CLI 实战,自然语言生成代码
android·人工智能·自动化·跨境电商·安卓自动化脚本·多账户运营
IT大白鼠8 小时前
PentestGPT作为AI运维编排工作流自动化底座的技术架构与应用价值评估
运维·人工智能·自动化·pentestgpt
zzzll11119 小时前
n8n 工作流自动化平台入门指南
运维·自动化
HXDGCL10 小时前
从“转盘困局”到“直线破局”:华创力科技PTS精密分度输送系统如何重塑自动化产线
运维·科技·自动化
戴西软件10 小时前
国内有哪些智能化RPA工具?——从“录数据”到“做判断”,国产数字员工正在重新定义自动化
运维·自动化·rpa
weixin_4038101311 小时前
iOS免越狱自动化三种方式对比:代理模式、蓝牙HID与OTG HID怎么选
ios·自动化·跨境电商·ios脚本·苹果群控·苹果投屏·苹果脚本
跨境小彭12 小时前
Temu半托管运营复盘:批量备货自动化实操解决方案
大数据·运维·自动化·跨境电商·temu
天远数科12 小时前
零信任架构实战:基于天远二手车VIN估值构建自动化汽车数据网关
人工智能·架构·自动化·汽车