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)
相关推荐
扛枪的书生1 小时前
AD 提权-NTLM 中继攻击(强制认证)
windows·渗透·kali·提权·域渗透
爱分享的飘哥1 小时前
第十九篇 自动化报表生成:Python一键生成可视化Excel图表与专业PDF报告,老板看了都点赞!
自动化·办公自动化·数据可视化·excel自动化·python报表·pdf报告
hqxstudying2 小时前
Java行为型模式---观察者模式
java·开发语言·windows·观察者模式
Damon小智3 小时前
玩转ClaudeCode:ClaudeCode安装教程(Windows+Linux+MacOS)
windows·ai·mac·wsl·claude code·vibe code
CHANG_THE_WORLD5 小时前
libimagequant windows 编译
windows·libimagequant
特种加菲猫6 小时前
构建完整工具链:GCC/G++ + Makefile + Git 自动化开发流程
linux·笔记·git·自动化
xchenhao14 小时前
基于 Flutter 的开源文本 TTS 朗读器(支持 Windows/macOS/Android)
android·windows·flutter·macos·openai·tts·朗读器
帽儿山的枪手16 小时前
追踪网络流量就这么简单 | 进阶篇 | conntrack
linux·windows·网络协议
王者鳜錸16 小时前
使用Selenium自动化获取抖音创作者平台视频数据
selenium·自动化·音视频
chao_78917 小时前
frame 与新窗口切换操作【selenium 】
前端·javascript·css·selenium·测试工具·自动化·html