winappdriver对已经打开的桌面软件做自动化
原因:软件无法从安装目录双击exe文件打开
解决方案:之前不知道winappdriver可以控制已经打开的窗口,后来在网络上找到办法,winappdriver可以把桌面当成一个窗口,先枚举桌面上的窗口,然后根据窗口名称获取到我们要测试的窗口的handle,此时就可以用这个句柄来新建一个driver。
参考:https://github.com/microsoft/WinAppDriver/blob/v1.0/README.md
https://blog.csdn.net/weixin_42152949/article/details/122255214
from appium import webdriver from selenium.webdriver.common.by import By desired_caps = {'app': 'Root', 'deviceName': 'windowsPC', 'platformName': 'Windows'} driver = webdriver.Remote( command_executor='http://127.0.0.1:4723', desired_capabilities=desired_caps) main_win = driver.find_element(By.NAME, 'xxxxxxxx') print(main_win) hd = hex(int(main_win.get_attribute("NativeWindowHandle"))) print(hd) caps = {'appTopLevelWindow': str(hd)} driver = webdriver.Remote( command_executor='http://127.0.0.1:4723', desired_capabilities=caps)
注:从这段代码可以看出,针对没有打开的软件,和已经打开的软件,新建driver时唯一的区别就是参数caps的区别,前者是app,后者是appTopLevelWindow
浙公网安备 33010602011771号