vendredi 29 janvier 2016

Automation.AddStructureChangedEventHandler doesn't work?

I'm trying to use System.Windows.Automation library to do some UI testing, and was able to make some progress, but I am unable to subscribe to the event of creating a popup window in my app. I've tried to use Automation.AddStructureChangedEventHandler on the root (desktop object) as well as on the window, but that didn't work. I also tried using different scopes, which also didn't help.

AutomationElement desktop = AutomationElement.RootElement;
AutomationElement app = desktop
    .FindFirst(TreeScope.Children,
        new PropertyCondition(AutomationElement.NameProperty,
            "Name of the App", PropertyConditionFlags.IgnoreCase));

ActivateWindow(app);

AutomationElement appWindow = app
    .FindFirst(TreeScope.Children,
        new PropertyCondition(AutomationElement.ControlTypeProperty,
            ControlType.Window));

// Find a button that opens a popup window and click it
AutomationElement button = appWindow
    .FindFirst(TreeScope.Children, Condition.TrueCondition)
    .FindAll(TreeScope.Children, Condition.TrueCondition)[8];

MoveMouseToAndClick(button);

Automation.AddStructureChangedEventHandler(desktop, TreeScope.Descendants, setupWindowOpen);

The setupWindowOpen handler fires sometimes, but it looks like that happens for other apps, not mine (I'm seeing Internet Explorer ids on the sender element object). Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire