【发布时间】:2020-10-09 09:02:32
【问题描述】:
我目前正在尝试使用 System.Windows.Automation 自动化 chrome 实例,但在某个时刻 AutomationElement.FindAll(TreeScope.Children, Condition.TrueCondition); 总是返回 0 个子级,但我可以在 inspect.exe 中看到它们。当我在 inspect.exe 中点击刷新时,元素也会显示在我的应用中。
在寻找解决方案时,我发现 this SO 帖子,该 OP 或多或少有相同的问题。 建议使用的答案:
SystemParametersInfo( SPI_SETSCREENREADER, TRUE, NULL, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
PostMessage( HWND_BROADCAST, WM_WININICHANGE, SPI_SETSCREENREADER, 0);
我将其实现为:
[DllImport("user32.dll", SetLastError = true)]
static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr pvParam, int fWinIni);
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
....
const int SPI_SETSCREENREADER = 0x0047;
IntPtr inptrnull = IntPtr.Zero;
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDCHANGE = 0x02;
IntPtr HWND_BROADCAST = new IntPtr(0xffff);
const int WM_WININICHANGE = 0x001A;
SystemParametersInfo(SPI_SETSCREENREADER, 1, inptrnull, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
PostMessage(HWND_BROADCAST, WM_WININICHANGE, SPI_SETSCREENREADER, 0);
但是没有效果。
我错过了什么? 还有其他/更好的方法吗?
【问题讨论】:
标签: c# user-interface ui-automation inspect.exe