开发者

automate ui - button event

I am trying to automate the clicking of my WPF application's button:

Details of the button using 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

I tried to do this:

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)ae开发者_如何学JAVADirectory.GetCurrentPattern(InvokePattern.Pattern);
ipClickDirectories.Invoke();
Thread.Sleep(1500);

and I still get the exception "No Edit Directory button".

What am I doing wrong?

I tried using AutomationID, ProcessID but to no avail.


Not sure what your ui tree structure looks like, but try changing TreeScope.Children to TreeScope.Descendants and see if that still doesnt work for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜