使用 UI 自动化单击应用程序中的按钮
Using UI Automation to click a button in an application
我正在尝试使用 UI 自动化单击第三方应用程序中的简单按钮。我已经初始化了 IUIAutomation 对象,并通过使用 ElementFromHandle() 函数和第三方应用程序窗口的句柄检索了 IUIAutomationElement。
但是我真的不知道如何使用这个IUIAutomationElement来查找按钮并发出左键单击它。
这是我到目前为止的代码:
void Control::clickButton()
{
for (std::list<Window>::iterator i = mainDetector.getWindowList().begin(); i != mainDetector.getWindowList().end(); ++i)
{
if (i->getTitle().find("PokerStars Lobby") != std::string::npos)
{
parentWindowHandle = (HWND)i->getHandle();
}
}
InitializeUIAutomation(iUiAutomation);
(*iUiAutomation)->ElementFromHandle(parentWindowHandle, iUiAutomationElement);
}
希望有人能帮助我如何从这里继续实际单击按钮
你可能会
发现使用TestStack.White(也可以从NuGet获得)来做这种事情更简单。它总结了许多UIAutomation,以便更轻松地编写驱动Windows应用程序的测试。
要查找目标按钮,您可以使用Windows 10 SDK中的"UIVerify"或"检查",它允许您查看桌面上所有窗口的UI自动化树。找到感兴趣的按钮后,您可以记下其 AutomationId 或其他属性,以用作TestStack.White
搜索命令之一或IUIAutomationTreeWalker
实例的搜索参数。
相关文章:
- 如何为应用程序中的某些按钮重置QApplication::styleSheet?
- 按下Arduino按钮后,如何在C#应用程序上执行操作
- 如何隐藏最大化和最小化按钮并在qml应用程序窗口中显示关闭按钮?
- MFC功能区主页按钮双击关闭应用程序
- 如何使MFC CToolbar按钮更加一致,以使Windows 7/10上的高DPI了解应用程序
- 如何从功能(C UWP应用程序)中修改按钮内容
- Qt3D应用程序在任何按钮按下时都会触发系统声音
- 是否可以报告用户在 Android 应用程序中单击了哪些按钮
- 禁用最大化按钮C 控制台应用程序
- 仅使用标题栏中的[X]按钮关闭MFC应用程序并禁用ESC快捷方式
- Qt:QVideoWidget 不显示并禁用应用程序中的所有按钮,或者极大地减慢应用程序的速度
- 如何在Qt应用程序中使用样式表更改QPush按钮图标大小
- 当在C#中的WPF应用程序中单击一个按钮时,如何调用C 代码
- 如何使用WindowsFormApplication按钮在两个Windows应用程序之间切换(强制它们顶部)
- 使用 UI 自动化单击应用程序中的按钮
- 禁用 Win32 C++中单个应用程序的按钮动画
- C++Windows窗体应用程序:当我单击当前窗体上的按钮时,如何显示以前的窗体
- 在后退按钮或关闭应用程序时调用析构函数
- 从没有任务栏按钮的c++启动c#应用程序
- 在Qt Widget应用程序中设置文本框和按钮的大小