NullReferenceException for text-boxes with same automation id but different name attribute

Nov 15, 2011 at 12:36 PM


I am exploring WHITE for automating a WIN32 application.  While I trying to automate the application log-in using WHITE, I encountered a NullReferenceException.  It was encountered in the statement #2 of the code below. I noticed that the application has 2 text-boxes with same automation id (65535) but different name attributes (USER ID & Password).  I am using UISPY to track the attributes of UI controls.

How to fix the code to handle the text-boxes? Please advise a suitable solution.

thanks in advance,




1. TextBox textBox = mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId("65535").AndByText("User ID"));

2. textBox.SetValue("admin");



System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.

Nov 15, 2011 at 1:51 PM


you can try to use UIAutomation to find the correct TextBox in the collection

and use

AutomationElementCollection coll = mainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "65535"));

find the correct in the collection (search for name or use And Property)

TextBox textBox = new TextBox(automationElement, mainWindow.ActionListener);




Nov 15, 2011 at 3:35 PM

Hi Throndorin,

Thank you for the response.  Are there any documented pointers on integrating & using UIAutomation with WHITE?  I couldn't find anything related with a quick search on Google.



Nov 16, 2011 at 7:07 AM

I don't know what is documented or what not

But White is only a Wrapper for UIAutomation and is based on it.

all White elements have an AutomationElement inside (ListViewCells, ListViewRows and so on have AutomationElementCollection)



Nov 22, 2011 at 4:37 AM

Hi Throndorin,

Thank you for your reply.  I could use UIAutomation (code below) to resolve the issue.  I have a query for you based on your recommendation touse UIAutomation.  Is it possible to use both the automation frameworks i.e. UIAUtomation and WHITE simulataneoulsy in a test script. For example, can we convert the mainWindow (in code below) of type AutomationElement to an object of type Window available in WHITE framework? I mean casting objects from one framework into another.  Alternatively, is it possible to get the Window object (of WHITE framework) from the AutomationElement object of UIAutomation framework?

Thanks & regards,




AutomationElement mainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Log On" ));
AndCondition cond1 = new AndCondition (new PropertyCondition(AutomationElementIdentifiers.NameProperty, "User ID" ), new PropertyCondition(AutomationElementIdentifiers.AutomationIdProperty, "65535" ));
AutomationElement control = mainWindow.FindFirst(TreeScope .Descendants, cond1);


Nov 22, 2011 at 7:00 AM
Edited Nov 22, 2011 at 7:02 AM

Hi rajendrasakpal


you can use both (UIAutomation and White) in the same skript without problems. White is a helper for UIAutomation not more not less. And White can only do thinks which can also be done with UIAutomation.

as far as I know exists no public constructor for Window, maybe there is an other class to generate a Window (a Factory or something else), the Admin here may ask this question, or have a deeper look in  the sources.

there is no cast operator from AutomationElement to UIItems but you can use the constructors of UIItems (as shown in my post before) to generate the needed UIItem type (Button, Listview,....).

Each UIItem contains a AutomationElement public porperty which can be used for UIAutomation.


hope that helps