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)
相关推荐
TH_113 小时前
35、AI自动化技术与职业变革探讨
运维·人工智能·自动化
武藤一雄15 小时前
C# 关于多线程如何实现需要注意的问题(持续更新)
windows·后端·microsoft·c#·.net·.netcore·死锁
代码方舟16 小时前
Java企业级实战:对接天远名下车辆数量查询API构建自动化风控中台
java·大数据·开发语言·自动化
coding消烦员18 小时前
在 Windows 内网搭建 Git 仓库:共享普通仓库 vs 中心 bare 仓库
windows·git
我送炭你添花20 小时前
Pelco KBD300A 模拟器:07+2.Python 专题:线程安全与信号槽机制——项目多线程最佳实践
python·自动化·运维开发
富唯智能21 小时前
重新定义“自动化搬运项目”:15分钟部署的复合机器人如何革新柔性生产
人工智能·机器人·自动化
Benny的老巢21 小时前
基于Playwright TypeScript/JavaScript的API调用爬虫成熟方案
javascript·爬虫·typescript·自动化·agent·playwright
北京耐用通信21 小时前
耐达讯自动化CAN转PROFIBUS网关让软启动器如何让包装线告别“信号迷宫”
人工智能·物联网·网络协议·自动化·信息与通信
xiaoliuliu123451 天前
IE8-WindowsXP-x86-CHS_23253_BDdl.exe 安装步骤(XP 32位简体中文版)
windows
百事牛科技1 天前
文件不想再加密了?取消Word 打开密码的方法
windows·word