首页 > 解决方案 > 在 MS Edge 浏览器的页面内找不到 UI 控件

问题描述

为客户的应用程序进行自动化测试 SSO 登录。应用程序使用授权页面打开默认浏览器 (MS Edge)。

我正在使用 MS UI 自动化来查找控件并采取行动。而且我还使用“Visual UI Automation verify”(VisualUIAVerifyNative)工具来检查控件。该工具完美地找到了我需要的一切。但我无法使用代码找到相同的元素。

我能够找到 Edge 窗口和一些控件,直到名为“m_webpageContent”的控件应该包含页面本身和其中的 Ui 控件。但是当我试图在其中找到元素时 - 我得到了空值。

var MainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants,
                    new AndCondition(
                        new PropertyCondition(AutomationElement.NameProperty, "Microsoft Edge"),
                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window)));

            var TheLayout = MainWindow.FindFirst(TreeScope.Descendants,
                    new AndCondition(
                        new PropertyCondition(AutomationElement.AutomationIdProperty, "m_webpageContent"),
                        new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group)));

var w = TheLayout.FindAll(TreeScope.Descendants,
                new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); // 0 elements

w = TheLayout.FindAll(TreeScope.Descendants,
                new PropertyCondition(AutomationElement.FrameworkIdProperty, "MicrosoftEdge")); // 0 elements

我也尝试使用 TreeWalker 来遍历控件树,但它也没有帮助......

这里有什么问题?我还能做什么?

谢谢!

标签: c#automationmicrosoft-edgeui-automation

解决方案


找到了解决方案。我用来发现 UI 控件的工具使用UIAComWrapped.dll。当我在我的自动化项目中引用它时,它开始查找所有“MicrosoftEdge”控件。


推荐阅读