栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

如何使用WinAppDriver绑定已存在的程序窗口(python)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用WinAppDriver绑定已存在的程序窗口(python)

本人的代码是基于python的,java的可参考底部链接。

1、创建Root窗口(即桌面窗口)会话

# 配置Root窗口
desired_caps = {'app': 'Root', 'deviceName': 'windowsPC', 'platformName': 'windows'}
# 创建Root窗口会话
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps)

2、在Root窗口会话中枚举你想要测试的程序窗口的句柄(可根据窗口名称枚举)

# 在Root窗口中根据 测试窗口的名称,获取句柄
main_win = self.driver.find_element(AppiumBy.NAME, "软件中心 - NW.js")
# 注意,句柄需要转为16进制
hd = hex(int(main_win.get_attribute("NativeWindowHandle")))

3、根据窗口句柄创建新会话

# 使用取到的句柄,配置测试窗口
caps = {"appTopLevelWindow": str(hd)}
# 建立测试窗口的会话
driver2 = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=caps)

4、操作你的测试窗口吧(比如点击测试窗口的升级按钮)

driver2.find_element_by_name("升级").click()

参考链接:

GitHub - microsoft/WinAppDriver at v1.0https://github.com/Microsoft/WinAppDriver/tree/v1.0#creating-a-desktop-session

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/686024.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号