Alex Marshall
Alex Marshall

Reputation: 10312

Get the AutomationElement for a WPF Popup

I'm working on a project that uses a popup in an editor to provide objects in a ListBox for users to double click in order to add them to their document. I'm trying to create automated tests for the app using the Automation API provided by microsoft, but I can't figure out how to get the AutomationElement for a Popup control, since it's in a different tree than my editor and its controls. Does anybody know how to get the AutomationElement for a WPF Popup ?

Upvotes: 6

Views: 1751

Answers (2)

Snowbear
Snowbear

Reputation: 17274

I've got popup AutomationElement for popup (OpenFileDialog in my case) from main window's children:

// I had automationElement for main window in advance
AutomationElement mainWindow = ... 

// Some condition to distinguish your popup from others
// if you may have more than one popup.
// Otherwise this condition might check ControlType == Window 
Condition popupCondition = ...

var popup = mainWindow.FindFirst(TreeScope.Children, popupCondition);

Upvotes: 0

Alex Marshall
Alex Marshall

Reputation: 10312

I wound up having to start at the Desktop and query through the automation tree using some very specific PropertyConditions combined with an AndCondition, using TreeScope.Descendants as a parameter for my queries.

Upvotes: 2

Related Questions