Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 用于Web应用程序的Microsoft UI自动化_Wpf_Selenium Webdriver_Browser_Ui Automation_Coded Ui Tests - Fatal编程技术网

Wpf 用于Web应用程序的Microsoft UI自动化

Wpf 用于Web应用程序的Microsoft UI自动化,wpf,selenium-webdriver,browser,ui-automation,coded-ui-tests,Wpf,Selenium Webdriver,Browser,Ui Automation,Coded Ui Tests,有人尝试过针对web应用程序的“Microsoft UI自动化”吗 我有一个WPF应用程序,它有一个嵌入式wpfbrowser。 由于这基本上是一个桌面应用程序,我不能使用SeleniumWebDriver 我尝试了CodedUI,但我面临一个问题,我在这里提出: 我计划使用UIAutomation,但再次表明我无法使用id属性识别控件 例: 但这是行不通的。“Clickme”为空 如何做到这一点是UIAutomation 编辑:附加屏幕显示: 我会尝试将树视图向下导航到您要查找的控件,而不是

有人尝试过针对web应用程序的“Microsoft UI自动化”吗

我有一个WPF应用程序,它有一个嵌入式wpfbrowser。 由于这基本上是一个桌面应用程序,我不能使用SeleniumWebDriver

我尝试了CodedUI,但我面临一个问题,我在这里提出:

我计划使用UIAutomation,但再次表明我无法使用id属性识别控件

例:

但这是行不通的。“Clickme”为空

如何做到这一点是UIAutomation

编辑:附加屏幕显示:

我会尝试将树视图向下导航到您要查找的控件,而不是根据死者进行导航。另外,您可以尝试的另一件事是,如果它为null,则执行重试循环。下面是FlaUI的一个通用示例。所以你的代码看起来像这样

 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));
var ps = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
                new PropertyCondition(AutomationElement.NameProperty, "Click Me"));

AutomationElement Clickme = elementMainWindow.FindFirst(TreeScope.Descendants, ps);
PropertyCondition ps=新的PropertyCondition(AutomationElement.automationdProperty,“but1”);
Func Func=()=>elementMainWindow.FindFirst(TreeScope.subjects,ps);
谓词重试=element=>element==null;
AutomationElement clickMe=重试.While(func,Retry,TimeSpan.FromSeconds(1));
因此,此代码将在1秒内重试查找该元素,如果该元素返回null或出现异常,则将重试查找该元素。如果发生上述任何一种情况,它将等待200毫秒,然后重试。这将告诉我,当您试图查找元素时,元素是否只是没有呈现,或者它们是否与inspect查找它们的方式和System.Windows.Automation查找它们的方式不同

如果这不起作用,我将发布一个使用tree walker的解决方案,但我建议在tree walker上使用此解决方案,因为如果这是一个应用程序,其他人可能希望针对其编写自动化,他们希望这些函数按照您尝试使用它们的方式工作。

不确定
是否等于automationId。如果可以在定义UI(XAML)的代码中使用该命名空间,则可以使用
AutomationProperties.AutomationId=“but1”
设置自动化id,该命名空间可能仅适用于WPF应用程序

在你的例子中,如果你的UI是用HTML定义的,我想你可以使用按钮的标题。 像这样

 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));
var ps = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button),
                new PropertyCondition(AutomationElement.NameProperty, "Click Me"));

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

ControlTypeProperty有助于按类型筛选结果。不是强制性的,但如果您有不同类型但具有相同名称属性的自动化元素,则它会有所帮助。

您可以截屏查看显示原始树视图层次结构的内容吗?如果我有,我可能会帮助你。@MaxYoung,我已经添加了截图。我希望这就足够了。