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)
相关推荐
2501_9032386519 分钟前
Git Bash:Windows下的强大命令行工具
windows·git·bash·个人开发
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
SuperherRo10 小时前
自动化反编译微信小程序工具-e0e1-wx
微信小程序·自动化·hook·反编译
学海无涯,行者无疆11 小时前
使用Jenkins实现Windows服务器下C#应用程序发布
windows·c#·jenkins·.net·cicd·自动发布·一键发布
做咩啊~12 小时前
windows设置暂停更新时长
windows
waicsdn_haha14 小时前
TeX Live 2025 最新版安装与中文环境配置全教程(Windows/Mac/Linux)
linux·windows·macos·论文笔记·sublime text·mdk·嵌入式开发工具
m0_7482382714 小时前
MySQL 实验1:Windows 环境下 MySQL5.5 安装与配置
windows·mysql·adb
扛枪的书生16 小时前
Windows 提权-SeBackupPrivilege 特权
windows·渗透·kali·提权