简体   繁体   English

Web应用程序的Microsoft UI自动化

[英]Microsoft UI Automation for Web Application

Has anyone tried "Microsoft UI Automation" for web application? 有没有人尝试过针对Web应用程序的“ Microsoft UI Automation”?

I have a WPF application which has a embedded wpfbrowser. 我有一个WPF应用程序,它具有嵌入式wpfbrowser。 Since this is basically a desktop app, I cant use Selenium Webdriver. 由于这基本上是一个桌面应用程序,因此我无法使用Selenium Webdriver。

I tried CodedUI but i am facing a issue, Which i have asked here: Coded UI - Unable to identify a html controls on a Wpfbrowser 我尝试了CodedUI,但遇到了一个问题,在这里我已经问过: 编码UI-无法在Wpfbrowser上识别html控件

I am planning to use UIAutomation, But again itseems that i am unable to identify a control using id property 我打算使用UIAutomation,但再次似乎无法使用id属性标识控件

Ex: 例如:

<button id="but1">Click Me</button>

For this i have: 为此,我有:

PropertyCondition ps = new PropertyCondition(AutomationElement.AutomationIdProperty, "but1");
AutomationElement Clickme = elementMainWindow.FindFirst(TreeScope.Descendants, ps);

But this is not working. 但这是行不通的。 "Clickme" is null. “ Clickme”为空。

How to do this is UIAutomation?? UIAutomation该怎么做?

EDIT: Attaching a screeshot: 编辑:附加一个screeshot: 在此处输入图片说明

I would try actually navigating the tree view down to the control you are looking for instead of doing it based on decedents. 我会尝试实际将树形视图导航到您要查找的控件,而不是基于后代。 Also another thing you could try is doing a retry loop if it is null. 另外,您可以尝试做的另一件事是如果它为null,则执行重试循环。 Here is an example of a generic Retry for FlaUI. 这是FlaUI的通用重试示例。 So your code would look something like this. 因此,您的代码将如下所示。

 PropertyCondition ps = new PropertyCondition(AutomationElement.AutomationIdProperty, "but1");

 Func<AutomationElement> func = () => elementMainWindow.FindFirst(TreeScope.Descendants, ps);
 Predicate<AutomationElement> retry = element => element == null;

 AutomationElement clickMe = Retry.While<AutomationElement>(func, retry, TimeSpan.FromSeconds(1));

So this code will retry finding the element for 1 second and will retry finding it if the element comes back null or it exceptions. 因此,此代码将重试查找元素1秒钟,如果元素返回null或异常,则将重试查找该元素。 If either of those happens it waits 200 milliseconds and tries again. 如果发生任何一种情况,它将等待200毫秒,然后重试。 This will tell me if the elements are just not rendered when you try to find them or if their is a difference between how inspect finds them and how System.Windows.Automation is finding them. 这将告诉我在尝试查找元素时是否仅不呈现元素,或者它们是否是检修如何找到它们与System.Windows.Automation如何找到它们之间的区别。

If this doesn't work I will post a solution using the tree walker but I suggest using this solution over the tree walker because if this was an application others would want to write automation against they would expect these functions to work the way you are attempting to use them. 如果这不起作用,我将发布一个使用Tree Walker的解决方案,但是我建议在Tree Walker上使用该解决方案,因为如果这是一个应用程序,其他人可能想针对其编写自动化程序,他们希望这些功能能够按照您尝试的方式工作使用它们。

Not sure if <button id="but1"> equals with automationId. 不确定<button id="but1">等于automationId。 You can set automation id using AutomationProperties.AutomationId="but1" if you can use that namespace in the code where you define your UI (XAML), which is probaly only for WPF applications. 如果可以在定义UI(XAML)的代码中使用该名称空间,则可以使用AutomationProperties.AutomationId="but1"来设置自动化ID,这仅适用于WPF应用程序。

In your case if your UI defined in HTML I think you can use the button's caption. 在您的情况下,如果您的UI是用HTML定义的,那么我认为您可以使用按钮的标题。 So something like this. 像这样

var ps = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
                new PropertyCondition(AutomationElement.NameProperty, "Click Me"));

AutomationElement Clickme = elementMainWindow.FindFirst(TreeScope.Descendants, ps);

ControlTypeProperty can help in filtering results by type. ControlTypeProperty可帮助按类型过滤结果。 Not mandatory, but it can help if you have automation elements with different type, but with same name property. 不是强制性的,但是如果您具有类型不同但名称属性相同的自动化元素,则可以提供帮助。

暂无
暂无

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

相关问题 使用Microsoft的Visual UI Automation验证 - Using Microsoft's Visual UI Automation Verify Microsoft UI 自动化库与编码的 UI 测试 - Microsoft UI Automation Library Vs Coded UI Test 如何判断元素是否与Microsoft UI Automation中的PropertyCondition匹配? - How can I tell if an element matches a PropertyCondition in Microsoft UI Automation? 订阅UI Automation事件会冻结窗口挂起的应用程序 - Subscribing to UI Automation event freezes application on window hang 用于基于Windows的WPF应用程序的UI自动化工具,具有记录和回放功能 - UI automation tool for a windows based WPF application with Record and Playback feauture 使用System.Windows.Automation和Microsoft.VisualStudio.TestTools.UITesting进行WPF UI测试自动化有什么区别? - What is the difference between using System.Windows.Automation and Microsoft.VisualStudio.TestTools.UITesting for WPF UI Test automation? 是否可以使用 Microsoft 自动化 UI 在 WPF/WinForm 应用程序上单击标签控件 - Is it possible to Click a label control on WPF/WinForm App using Microsoft Automation UI 当应用程序通过UI自动化测试启动时,ContentControl不可见,但是当应用程序由用户启动时,它可见 - ContentControl is not visible when application starts via UI Automation test, but its visible when application starts by user UI自动化和功能区控件 - UI Automation and Ribbon control 过时的 UI 自动化树 - Outdated UI automation tree
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM