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)
相关推荐
夜雪一千10 小时前
Python enumerate() 函数完整详解:遍历同时获取索引,告别手动计数
服务器·windows·python
BJHHZX199113 小时前
北京华恒智信为制造行业破解自动化伪升级难题,落地人机协作三阶段减编增效方案
自动化·绩效考核·人力资源管理·人机协作·员工激励
程序员吕洞宾15 小时前
开源多维表格SmartTable V1.6:自动化工作流,把重复操作交给系统即可
开源·自动化·github·多维表格·飞书多维表
2301_7803039016 小时前
网络安全、自动化运维、ERP、CRM、MES
运维·web安全·网络安全·自动化·安全威胁分析
csg110716 小时前
电路板抗干扰:电容、电感和弧线布线的应用
单片机·嵌入式硬件·物联网·自动化
环境栈笔记17 小时前
多账号浏览器选型检查清单:Profile、权限、Session 和任务日志怎么评估
前端·人工智能·后端·自动化
jieyucx17 小时前
Shell实战:无限循环监控Nginx服务,异常自动重启+双份日志留存
linux·运维·nginx·自动化·shell
workflower18 小时前
室内外配送机器人-应用路径
人工智能·机器学习·设计模式·矩阵·自动化
Black蜡笔小新19 小时前
自动化AI算法训练服务器DLTM零代码私有化赋能智慧农业用AI智能视觉守护万亩良田
人工智能·算法·自动化
初雪云19 小时前
iOS 上架入门:证书、描述文件、IPA 上传到底是什么关系?
android·ios·自动化·产品经理·iphone