How to convert AutomationElement to White.Core.UIElements

Aug 5, 2010 at 3:32 PM

Hi All,

I would like to know if its possible to convert an AutomationElement to White.Core.UIElements type?

Best regards,

Aug 6, 2010 at 6:28 AM

Hi

I think you mean elements like Button and so on, right?

 

so do the following

 

Example:

 

AutomationElement buttonElement = window.GetElement(SearchCriteria.ByAutomationID("button");

Button button = new Button (buttonElement, window.ActionListener);

 

 

Throndorin

Aug 8, 2010 at 8:46 AM

Hi,

Thank you for your help, the example code was useful.

 

Ahmed Hidri

Mar 24, 2011 at 4:48 PM

Hi,

Is there any possible way to convert or cast an AutomationElement to a White UIItem without using the .GetElement or .Get functions? I am finding that when using those functions in my test app, there are too many controls, and so White gets stuck when trying to return the List Collection (and I am unable to change the search depth with any performance increase). 

Of course when I try to cast the AutomationElement to a White Core Item, I get this error:

Cannot implicitly convert type 'System.Windows.Automation.AutomationElement' to 'White.Core.UIItems.IUIItem'

 

Mar 25, 2011 at 7:45 AM

Hi

 

there is no cast !

The reason is that the AutomationElement is a member of a UIItem or a derived Class.

The way to get the AutomationElement can completly  performed without White, but if you need later a UIItem or an other specialized class you had to use the cosntructor.

If you dont want to use the GetElement operation you can break down to UIAutomation =>

 

AutomationElement mainWindowAE =  window.AutomationElement.

 

=> now  you can use the Find or FindFirst Method of Automation Element to find your AutomationElement.

AutomationElement myFoundAutomationElement = mainWindowAE.Find(.........................................

UIItem item  = new UIItem(myFoundAutomationElement, mainWindow.ActionListener);

 

hope that helps, for more information about how to find elements on AutomationElements have a look in the msdn

Throndorin

 

 

 

Mar 25, 2011 at 3:03 PM

Yes! Thank you much! This is the trick I was looking for:

AutomationElement cElem = window.AutomationElement.FindAll(TreeScope

.Descendants, cond)[iIndex];

White.Core.UIItems.MultilineTextBox textbox = new White.Core.UIItems.MultilineTextBox 

(cElem, window.ActionListener);

 

Mar 29, 2011 at 8:47 PM

How come the TreeItems.Tree constructor does not take these same parameters? I cannot do this:

White.Core.UIItems.TreeItems.Tree cTree = new White.Core.UIItems.TreeItems.Tree(AutomationElement, window.ActionListener)

How can I create a new Tree from an AutomationElement?

Thanks again, Will

Mar 30, 2011 at 7:13 AM
Edited Mar 30, 2011 at 7:14 AM

Hi

 

I'm not sure why but the cosntructor for Tree is "internal", no idea what the reason is.

 

you can try something like this

 

AutomationElement element = window.Find........;

Tree tree = (Tree)(new UIItem( element, window.ActionListener ));

Throndorin

Mar 30, 2011 at 2:48 PM

Hi

Trying to cast a UIItem to a Tree as in your example above gives this error:

Unable to cast object of type 'White.Core.UIItems.UIItem' to type 'White.Core.UIItems.TreeItems.Tree'.

Given this, it looks like a TreeView is only accessible using the White window.Get functions?

Thanks,

Will

Mar 31, 2011 at 6:40 AM

Ok,

 

than two steps back.

Why you can't get the Tree directly using White, maybe there is another way.

 

Throndorin

Feb 2, 2012 at 8:05 AM

I have two questions:

 1. Does white support wildcard for the window caption? se

// Find the main window

 

window = (Core.UIItems.WindowItems.WPFWindow)application.GetWindow("Window1*", Core.Factory.InitializeOption

.NoCache);

 

Assert.IsNotNull(window);

This code will always failed because it can not find window with title Window1*.

2. Where can I get more detailed document about how to use white?

The simple object like button and textbox we know how to use it, but for the complex object like datagrid, menuitem and listview, I don't know how to use it, so I realy want a detailed document about our white.core.dll library.

Feb 2, 2012 at 2:58 PM
Edited Feb 2, 2012 at 3:01 PM

1. You can’t use wildcards for captions out of the box that I know of, but you can use partial matches with RegEx like this:

windows = Desktop.Instance.Windows();

Regex.IsMatch(windows[index].Name, ".*" + MyWindowSearchValue + ".*" //loop through the windows List to find your matching one

 

 

2. Honestly, it has been a lot of trial and error to find out how to use other elements. I ended up making my own custom datagrid object, because the White one had some issues. The listview and menuitems are pretty straight forward once you start using them. But I have mixed the Windows Automation with White quite a bit to achieve full capability with all elements.