Windows 应用程序驱动程序处理 Windows 资源管理器窗口 [英] Windows Application Driver handle windows explorer window
问题描述
我正在尝试自动化 Windows 桌面应用程序,一切都很好,直到在我的应用程序中的一个步骤中,我必须单击浏览"按钮打开 Windows 资源管理器窗口以选择图像并加载它.
I'm trying to automate a windows desktop application and everything is fine until in one of the steps in my application, I have to click on a "Browse" buttom that opens a windows explorer window to select an image and load it.
问题是我不知道如何让 WinAppDriver 聚焦在这个新窗口中,以便能够选择图像并加载它.
The thing is that I do not know how to make WinAppDriver focus in this new window, to be able to select the image and load it.
这是桌面应用程序的一部分,发送时点击浏览:
This is a part of the desktop application, and when sending click on Browse:
推荐答案
您可能需要 winappdriver 将其当前句柄更改为新资源管理器窗口中的句柄.我不确定 Python 语法,但在 C# 中,您可以这样做:
You probably need winappdriver to change its current handle to the one from the new explorer window. I'm not sure about the Python syntax, but in C# you do it like this:
driver.SwitchTo().Window(Driver.WindowHandles.Last());
Last()
函数只选择最近添加的 windowHandle.确保保留之前的窗口句柄,以便在资源管理器窗口关闭后切换回来.
The Last()
function just selects the most recent added windowHandle.
Make sure you keep your previous window handle around, so you can switch back once the explorer window closes.
还可以看看这些帖子.它是关于 webdriver 但功能是相似的:
Also take a look at these posts. Its about webdriver but the functions are similar:
这篇关于Windows 应用程序驱动程序处理 Windows 资源管理器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!