简体   繁体   English

C#TestStack.White-从最小化的窗口正确获取Window.Items

[英]C# TestStack.White - Get Window.Items correctly from an minimized Window

I am currently using the TestStack.White framework to retrieve informations from an external Window . 我目前正在使用TestStack.White框架从外部Window检索信息。

When the Window.DisplayState is Restored or Maximized , I can perfectly get the items that I want...but when it is Minimized , I am not able to see every item from the Window... the following examples shows the Google Chrome Items using commands in the Visual Studio Immediate Window : Window.DisplayState 恢复最大化时 ,我可以完美地获取所需的项目...但是当其最小化时 ,我无法从Window中看到每个项目...以下示例显示了Google Chrome项目在Visual Studio 即时窗口中使用命令:

MAXIMIZED WINDOW: 最大化的窗口:

Window.DisplayState (COMMAND)
Maximized
Window.Items (COMMAND)

Count = 35
[0]: {Panel. AutomationId:183101736, Name:Chrome Legacy Window, ControlType:painel, FrameworkId:Win32}
[1]: {MenuBar. AutomationId:SystemMenuBar, Name:Barra de menus do sistema, ControlType:barra de menus, FrameworkId:Win32}
[2]: {Button. AutomationId:Minimize, Name:Minimizar, ControlType:botão, FrameworkId:Win32}
[3]: {Button. AutomationId:Restore, Name:Restaurar, ControlType:botão, FrameworkId:Win32}
[4]: {Button. AutomationId:Close, Name:Fechar, ControlType:botão, FrameworkId:Win32}
[5]: {CustomUIItem. AutomationId:, Name:Google Chrome, ControlType:personalizado, FrameworkId:}
[6]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[7]: {Button. AutomationId:, Name:Murilo, ControlType:botão, FrameworkId:}
[8]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[9]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[10]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[11]: {Tab. AutomationId:, Name:, ControlType:guia, FrameworkId:}
[12]: {Button. AutomationId:, Name:Nova guia, ControlType:botão, FrameworkId:}
[13]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[14]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[15]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[16]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[17]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[18]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[19]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[20]: {Button. AutomationId:, Name:Fechar, ControlType:botão, FrameworkId:}
[21]: {ToolStrip. AutomationId:, Name:main, ControlType:barra de ferramentas, FrameworkId:}
[22]: {Button. AutomationId:, Name:Recarregar, ControlType:botão, FrameworkId:}
[23]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[24]: {Button. AutomationId:, Name:Adicionar esta página aos favoritos, ControlType:botão, FrameworkId:}
[25]: {CustomUIItem. AutomationId:, Name:Extensões, ControlType:personalizado, FrameworkId:}
[26]: {Button. AutomationId:, Name:AdBlock - clique para detalhes, ControlType:botão, FrameworkId:}
[27]: {Button. AutomationId:, Name:Tampermonkey, ControlType:botão, FrameworkId:}
[28]: {ToolStrip. AutomationId:, Name:Favoritos, ControlType:barra de ferramentas, FrameworkId:}
[29]: {Button. AutomationId:, Name:AAA, ControlType:botão, FrameworkId:}
[30]: {Button. AutomationId:, Name:BBB, ControlType:botão, FrameworkId:}
[31]: {Button. AutomationId:, Name:CCC, ControlType:botão, FrameworkId:}
[32]: {Button. AutomationId:, Name:DDD, ControlType:botão, FrameworkId:}
[33]: {Button. AutomationId:, Name:EEE, ControlType:botão, FrameworkId:}
[34]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}

MINIMIZED WINDOW: 最小化的窗口:

Window.DisplayState (COMMAND)
Minimized
Window.Items (COMMAND)

Count = 19
[0]: {MenuBar. AutomationId:SystemMenuBar, Name:Barra de menus do sistema, ControlType:barra de menus, FrameworkId:Win32}
[1]: {Button. AutomationId:Restore, Name:Restaurar, ControlType:botão, FrameworkId:Win32}
[2]: {Button. AutomationId:Maximize, Name:Maximizar, ControlType:botão, FrameworkId:Win32}
[3]: {Button. AutomationId:Close, Name:Fechar, ControlType:botão, FrameworkId:Win32}
[4]: {CustomUIItem. AutomationId:, Name:Google Chrome, ControlType:personalizado, FrameworkId:}
[5]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[6]: {Button. AutomationId:, Name:Murilo, ControlType:botão, FrameworkId:}
[7]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[8]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[9]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[10]: {Tab. AutomationId:, Name:, ControlType:guia, FrameworkId:}
[11]: {Button. AutomationId:, Name:Nova guia, ControlType:botão, FrameworkId:}
[12]: {ToolStrip. AutomationId:, Name:main, ControlType:barra de ferramentas, FrameworkId:}
[13]: {Button. AutomationId:, Name:Recarregar, ControlType:botão, FrameworkId:}
[14]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}
[15]: {Button. AutomationId:, Name:Adicionar esta página aos favoritos, ControlType:botão, FrameworkId:}
[16]: {CustomUIItem. AutomationId:, Name:Extensões, ControlType:personalizado, FrameworkId:}
[17]: {ToolStrip. AutomationId:, Name:Favoritos, ControlType:barra de ferramentas, FrameworkId:}
[18]: {CustomUIItem. AutomationId:, Name:, ControlType:personalizado, FrameworkId:}

As you guys can see, the above example shows 35 items when the Window is Maximized , meanwhile the Minimized Window is showing only 18 items. 大家可以看到,当Window 最大化时,上面的示例显示了35个项目,而Minimized Window仅显示了18个项目。

If I want the Panel 183101736 (first position in Maximized Window ), it can be easily get using the following code: 如果我想要Panel 183101736( 最大化 Window第一个位置),可以使用以下代码轻松获得:

TestStack.White.UIItems.Panel panel = Window.Get<TestStack.White.UIItems.Panel>(SearchCriteria.ByAutomationId("183101736"));

If the Window is Minimized , I have to change its state manually using Window.DisplayState = DisplayState.Maximized ... otherwise, it will raise the following Exception . 如果将Window 最小化 ,则必须使用Window.DisplayState = DisplayState.Maximized ...手动更改其状态,否则,它将引发以下Exception Is there a way to get "every" item without forcing the Window to be opened? 有没有一种方法可以在不强制打开Window情况下获取“每个”项目?

AutomationException

I think UIItems are only around, if they are rendered. 我认为UIItems仅在渲染时出现。 A minimized window does not get rendered, so there are no UIItems to be found. 最小化的窗口不会被渲染,因此找不到UIItems。 To get the Items the window needs to be active, not minimized and in the foreground. 要获取项目,窗口需要处于活动状态,而不是最小化,并且处于前台。

Here is a question about the last part: Is there any way to activate a window with White? 这是关于最后一部分的问题: 是否可以用White激活窗口?

It is essentially like WebScraping with these modern javascript-pages, you can't scrape something, that is not loaded in dom yet. 从本质上讲,就像使用这些现代javascript页面进行Web抓取一样,您无法抓取尚未加载到dom中的内容。 As opposed to an rest-service (or for windows-automation a proper ipc) it handles with the rendered interface, 'emulating' a human user - and limited to the items he would be presented. 与休息服务(或用于Windows自动化的适当ipc)相反,它使用呈现的界面来处理,“模拟”人类用户-并且限于他将要呈现的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM