This project is read-only.

Retrieve all text objects that begin at a specific X coordinate

Nov 3, 2010 at 7:25 PM

I have a screen that contains data  (several TextBlock objects).  It looks like a table but it's not.   I need to retrieve all the objects with a specific Bounds.X  coordinate.  How do I do that?   I am new to White and to UI automation in general and spent a lot of time trying different techniques but was unable to get anywhere.

I tried a while loop that retrieves all the text objects, retrieve the Bounds property for each and check if the X coordinate is 250.  If yes, add to an IUItems[].   However that was unsuccessful as well especially when adding the value.  Here is the sample code.

int iLoop; iCnt;
Rect TypeRect;
IUItem[] Types;
iCnt = 0;
Types = null;
IUItem[] AllLabels = MainWindow.Subwindow.GetMultiple (SearchCriteria.ByControlType(ControlType.Text));
for (iLoop=0; iLoop<=AllLabels.Length-1; iLoop++)
  TypeRect = AllLabels[iLoop].Bounds;
  if (TypeRect.X == 250){
    Types[iCnt] = AllLabels[iLoop];

I am getting an error in the line where adding the AllLabels Item whose X coordinate is 250 to Types Array  that the Ojbect reference not set to an instance of an object.

Any ideas?   Thank you very much.



Nov 4, 2010 at 9:27 AM


try this



List<Label> types = new List<Label>();

foreach(Label label in AllLabels)

   if (label.Bounds == null

   if (label.Bounds.X == 250)