我正在尝试自动点击我的WPF应用程序按钮:
使用UISpy.exe的按钮的详细信息:
AutomationElement
General Accessibility
AccessKey: ""
AcceleratorKey: ""
IsKeyboardFocusable: "True"
LabeledBy: "(null)"
HelpText: ""
State
IsEnabled: "True"
HasKeyboardFocus: "False"
Identification
ClassName: "Button"
ControlType: "ControlType.Button"
Culture: "(null)"
AutomationId: "JumptodirectoryButton"
LocalizedControlType: "button"
Name: "Edit Directories"
ProcessId: "5784 (GUI)"
RuntimeId: "7 5784 46496694"
IsPassword: "False"
IsControlElement: "True"
IsContentElement: "True"
Visibility
BoundingRectangle: "(1683, 885, 104, 23)"
ClickablePoint: "1735,896.5"
IsOffscreen: "False"
ControlPatterns
Invoke
我试着这样做:
AutomationElement aeDirectory = null;
aeDirectory = aeMasterBuild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Edit Directories"));
if (aeDirectory == null)
throw new Exception("No Edit Directory button");
else
Console.WriteLine("Edit Directory button present");
Console.WriteLine("Clicking on edit directories button");
InvokePattern ipClickDirectories = (InvokePattern)aeDirectory.GetCurrentPattern(InvokePattern.Pattern);
ipClickDirectories.Invoke();
Thread.Sleep(1500);
我仍然得到例外情况“没有编辑目录按钮”。
我做错了什么?
我尝试使用AutomationID
,ProcessID
,但无济于事。
答案 0 :(得分:0)
不确定你的ui树结构是什么样的,但是尝试将TreeScope.Children更改为TreeScope.Descendants,看看它是否仍然不适合你。