Useful set of utility functions for Coded UI Test!

We have collected various internal and external feedback and built up a library of utility functions for Coded UI Test for various Web\Win\WPF controls.  These APIs will work on VS2010 RC (30128.01) or later only (if you have not moved, good time to do it now). 

The table of all the APIs with example usage is below.  Some important ones are –

  • Find column names and column values for List View controls.
  • Get content of controls like Data Grid or List and validate it in one shot.
  • Get tool tip text of control
  • Find broken links on the page

Refer attachment, it contains 3 files –

  • The UITestingUtilities.dll (library assembly)
  • The UITestingUtilities.xml (the document file for VS) and
  • The UITestingUtilities.mht (the help file)

To use, unzip the files on the disk and add reference to the dll.  As you use these APIs, do send me your feedback, bugs and anything else missing.  Based on the feedback, we will absorb some of these APIs into the product itself.

Note that this is not a product binary and hence not supported by us.  However, if you do find an issue, please report to me and I will do my best to get the fix out.

Comments (64)

  1. SteveHarris says:

    Thanks for putting these utilities together for all of us out here Gautam. I would like to use your method "FindFirstCellWithValue" but it appears the code only looks at TD cells and does not include TH cells. Could you either post the code for this method so we can modify it or could you modify the function to look at both TD and TH cells? Thanks for any help you can provide.

  2. Thanks Steve for using Coded UI Test and this utility.

    Something like this should do the trick –

           /// <summary>

           /// Finds the first header cell with the given value.

           /// </summary>

           /// <param name="table">The HtmlTable object.</param>

           /// <param name="value">The value to find for.</param>

           /// <returns>The first header cell with the value.</returns>

           /// <remarks>

           /// Example – Find first header cell with value ‘Coded UI Test’.

           ///     HtmlHeaderCell cell = myTable.FindFirstHeaderCellWithValue("Coded UI Test");

           /// </remarks>

           public static HtmlHeaderCell FindFirstHeaderCellWithValue(this HtmlTable table, string value)


               if (table == null) throw new ArgumentNullException("table");

               // Set properties on the cell and return.

               HtmlHeaderCell cell = new HtmlHeaderCell(table);

               cell.SearchProperties[HtmlHeaderCell.PropertyNames.InnerText] = value;


               return cell;


    The actual code is same as above – just that it uses HtmlCell instead of HtmlHeaderCell.


  3. stgn says:

    Can you provide a code example that shows, how one can access the text of a certain cell of a ListView?

  4. Naresh says:

    This is really helpful.Thanks Gautam.

  5. Mairead says:

    Hi Gautam,

    I'm using some functions from your testing utilities in my tests, I have added the .dll to the root of my project folder and have added the dll as a reference to my project and checked the project back into TFS. This is all fine, but when I get the latest version of my solution (and overwrite all files even if latest version matches local version), I am receiving an error after building regarding the .dll, I have to remove the reference and then re-add the reference to my project again to rectify it.

    Any ideas on why this is happening? For some reason the solution builds fine in debug mode.

  6. Sorry for late reply.  For some reason, my blog settings got messed up and I had trouble login in.  In general, the Coded UI Test forum (…/threads) is better place to post your questions as that is monitored by many folks & you will get faster response.

    @Naresh – Thanks.

    @Mairead – No idea.  If you could, post your solution at the above forum and someone might be able to help.

    @stgn – You can use WinList.GetColumnValues() to get the cell values.  This returns an string array which is the value of all the cells.



  7. VIjay says:

    There is no metnod GetColumnValues()  in WinList Class .Can you please give an example of how to retreive ListView Column value

  8. @vijay – In the attached dll, you will find three extension methods –

     1. WinList.GetColumnNames() – Use this to get the names of the columns of the WinList.

     2. WinListItem.GetColumnValues() – Use this to get a row of data i.e. all the cells of given list view item.

     3. WinList.GetContent() – Use this to get the entire table of data as one dimensional array.

  9. Vijay says:

    in related to my previos query when i use WinExtensions.GetColumnValues is gives error Invalid IO Operation stating "The control passed is not a list view item control.  This operation is valid only for list view item control."

               foreach (WinControl control in wkList.Items)


                    WinListItem listItem = new WinListItem(control);

                   string[] strSubItems = WinExtensions.GetColumnValues(listItem);


  10. Please put a post on…/threads with proper details for someone to follow up on this.


  11. Vijay says:

    This is my window application code for listview :-

             // Create three items and three sets of subitems for each item.

               ListViewItem item1 = new ListViewItem("item1", 0);




               ListViewItem item2 = new ListViewItem("item2", 1);




               ListViewItem item3 = new ListViewItem("item3", 0);

               // Place a check mark next to the item.

               item3.Checked = true;




               // Create columns for the items and subitems.

               // Width of -2 indicates auto-size.

               listView1.Columns.Add("Item Column", 100, HorizontalAlignment.Left);

               listView1.Columns.Add("Column 2", 100, HorizontalAlignment.Left);

               listView1.Columns.Add("Column 3", 100, HorizontalAlignment.Left);

               listView1.Columns.Add("Column 4", 100, HorizontalAlignment.Center);

               //Add the items to the ListView.

               listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });

    Then i add the lisview control in Coded UI test  :-

    In the coded UI test i used below code

    WinList wkList = this.UIForm1Window.UIListView1Window.UIListView1List;

               string[] strVal = CommonExtensions.GetValuesOfControls(wkList.Items);

               foreach(WinControl control in this.UIForm1Window.UIListView1Window.UIListView1List.Items)


                   int count = control.GetChildren().Count;

                   object objVal = CommonExtensions.GetValue(control);

                   WinListItem lstItem = (WinListItem)objVal;


    in the "strVal " variable gives only values of first column not the subitems.

    in add watch window i get below mentioned value:-

    strVal[0] = "item1"

    strVal[1] = "item2"

    strVal[2] = "item3"

    I have also tried

    WinListItem listItem = new WinListItem(control);

    string[] strSubItems = WinExtensions.GetColumnValues(listItem);

    But i am getting Invalid Io expection stating "The control passed is not a list view item control.  This operation is valid only for list view item control."

    Please can you give me code snippet to acces List View Subitems.

    Let me know if you require any more information.

    I have also posted the query in…/threads

  12. keshav says:

    hi, can any one tell me how to get values from a html table as i am new to coded ui where to write code in designer or in .cs file.please give the code. i am confusing in writing the code whether in .cs or designer file.can u please give clear picture?

    thanks in advance

  13. You can use table.GetContent() to get the an string[] which is the content of entire table as one dimensional array walking left to right and top to bottom.

    You should not change the *.designer.cs file ever.  Please refer my blog…/why-is-coded-ui-test-generated-code-not-a-straight-line-code.aspx to understand the generated code and how to best customize the code.


  14. keshav says:

    Hi Gautham,

    I am working with coded ui newly. really  its features are good. i had a problem in when dragging cross hair on control its class name showing as html table. but  its id as doubt is,what should i consider for as control type is it a grid or a html there any difference?.and also i need to capture each cell data and compare with table is just like given below.please click the link. if possible give some code.

    its urgent.

    thanks in advance

  15. In Coded UI Test, there is nothing like Grid but only Tables to avoid confusion.  From your description above, it is difficult to figure out the issue.  I suggest you post on the forums – refer…/forums-are-the-best-place-to-ask-questions.aspx – with complete information like the repro steps, what behavior you are seeing in details and the logs.  For logs, check out…/how-to-enable-tracing-for-ui-test-components.aspx.


  16. brooke28 says:

    Hi Gautam…First off thanks for giving us this DLL..I am using those methods a lot..

    Is it possible to get the souce code as well,since that might help us tackle similar situations in our scenarios…Thanks again…

  17. achin says:

    Can we get the source code as well for this.It might really help us to write better automation code.

  18. @Brooke and @Achin – Let me check on the formalities around this and get back.

  19. EY says:


    I would like to add this dll file, and give it a try.  What is the directory path I should use?

    Thank you

  20. @Ey – There is no strong requirement on the directory path – you could copy it anywhere and add reference.  My advice would be to copy it to sub-dir of your project dir.  If you are using version control, then checkin the dll too.

    Note that the reference should be CopyLocal = True (which is default) for the buildtest to deploy it for execution.

  21. sharepointUser says:

    Hey Gautam. I am interested in your fourth point. Identifying broken links. I am looking at running a script that can traverse all parent , child and grandchild etc links in sharepoint application and get me the list of broken links. Do you have any readymade code for the same? since we are from the testing community, we have limited coding exposure.


  22. Sharepoint user says:

    Hi. Do u have a code for checking the sharepoint site for broken links by traversing parent/children/grandchildren links and so on. A complete test for broken links. Kindly help.


  23. @Sharepoint User – Please check various overloads of IsBrokenLink function in the attached library.  For example, using Coded UI Test, you can get an HtmlDocument and then call FindAllBrokenLinks() function on it.  The attached zip contains help file.


  24. sowjanya says:

    how can i get all the rows of a wpf table

  25. There is WpfTable.Rows property!

  26. Otto Sporteman says:

    Hi Gautam! I'm having a problem with the UITesting Utilities method GetContent().

    While debugging it's bringing the same results as GetColumnNames().

    Is this a known issue?


  27. Is this custom control or standard Windows Forms Data Grid?  I have not tested this for custom controls.

  28. Hi Gautam,

    While trying to use this dll, I added its reference in my project. But at runtime, when i try and access its methods it gives me following error :

    uIItemList.GetColumnNames() 'Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinList' does not contain a definition for 'GetColumnNames' and no extension method 'GetColumnNames' accepting a first argument of type 'Microsoft.VisualStudio.TestTools.UITesting.WinControls.WinList' could be found (are you missing a using directive or an assembly reference?)    

    Can you suggest why is it not able to get the definition of methods and what else needs to be done to rectify this

  29. @Tanmay – This means that the dll is not getting deployed properly.  Ensure "CopyLocal" property of this reference in VS is set to true.

  30. dak1 says:

    Quick question.  I was hoping that this would solve some of our old MFC / ATL automation problems.  I've got an ATL dialog with a list view, which can be captured as a WinList.  Surprisingly, I can capture the WinListItems in it, being that it's kind of a custom control, but not the sub items.  The 2nd column of each list item has a check box that I'm trying to get to.  The odd thing is that UI spy sees these sub items as children of the WinListItem but calling GetChildren with the WinListItem returns nothing.

    Anyway, If I try to use GetColumnValues() on a WinListItem, or GetContent() on the parent WinList, it throws an ArgumentOutOfRangeException "Length cannot be less than zero, Param name: 'length' ".  

    I suppose that's out of your control, unless it's something you're doing in GetColumnValues().  Here's the stack trace:

    at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) at System.String.Substring(Int32 startIndex, Int32 length) at Microsoft.VisualStudio.TestTools.UITesting.WinExtensions.GetColumnValues(WinListItem listViewItem)

    I may be too optimistic to think that we can fully automate our old ATL dialogs.  I'm guessing your extensions are pretty much confined to WinForms or built-in Wpf controls.  

  31. There are some known limitations with ATL and MFC.  Please post at…/threads and see if someone in the community can help you here.


  32. Madhu says: there any property like Columns  for HtmlTable like for server side control, so that I can access a column by index. Can we add the methods or properties for Html controls that are similar to server controls?

    Thanks In Advance…

  33. @Madhu – The Coded UI Test works on the Client UI and hence would work only on the client side objects.  Your server control will get transformed to appropriate HTML in client side and you have to figure that out & use appropriate API.


  34. Jusus Rivera says:

    I am working on an automation script for a .Net application. I would like to use this utilities file in order to get the value of each of the cells in a ListView (WinList). Can anyone please direct me on how to start with this utilities file?

     –I've already made reference to the .dll file in my project. But how do I refer to its methods in the script code?

  35. @Jusus – Refer the mht file in the zip for help.

  36. Madhu says:

    Hi.. Thank you for your reply.  Can we compare strings in Coded UI test by using String methods. When I use string.equals() or, even though strings are same it is not working. I need boolean as return value. Assert.AreEqual() returns void. Is there any api for that? I know there is A Test Api available. But I have not used it.


  37. Yes, you should be able to use String.Equals and String.Compare.  See if your strings are case-sensitive.  If so, you need to ask String.Equals to ignore case.


  38. Madhu says:

    Hi..Thankyou for your reply. The issue was resolved. I am not  getting HtmlProperties in intellisense to add in search properties. For example this.UIMapWorkgroup.UISelectUserMicrWindow.UISelectUserDocument.UIGvDataTable1.UIAdminHyperlink.SearchProperties.Add(HtmlProperties.).Do  i need to add any reference to a dll.  


  39. The HtmlProperties are string and won't come in Intellisense.

  40. IsBrokenLink does not work well says:

    Sometimes, we can open a link through IE. But when we use IsBrokenLink to test it, it returns true. It's not always the case, the it sometimes happens.

    Is there some timeout mechanism for it ? Maybe it fails because the web performance is not very good ?

  41. Yes, there is a default timeout (same as WebRequest.Timeout as mentioned at…/  To change the timeout, you can use overload of IsBrokenLink API and specify your own timeout.

  42. Angel says:

    Hi I'm farely new to coded ui test 2010. I am trying to use your utility to find a count for all the hyperlink with id =xxxxsample in my container, but when I add a reference to the UITestingUtilities it give me an error. Can you help me with this?

    Thanks a million

  43. @angel – What is the error you are seeing?  Use the "Email Blog Author" link above to send me the error.

  44. Saiprasad Rao says:

    Hi Gautam,

    I am not able to run recorded content when the grid control having checkbox control.  what is the solution for this.

    Following is the error

    Another control is blocking the control. Please make the blocked control visible and retry the action. Additional Details:

    TechnologyName:  'MSAA'

    Name:  'row 1, column 0'

    ControlType:  'CheckBox'

    Thanks, Saiprasad Rao

  45. @sai – The error indicates that there are two controls completely overlapping each other.  The control that you are trying to access is one that is below the other control and hence the failure.

    Beyond this it is difficult to sayfix the issue.  You should debug it yourself and if the problem is still not solve, try forum –…/threads

  46. Kiran Dasari says:

    Hi Gautam,

    Hi, I am Automating an Web Application , Recently there was a new deployement of code from Dev to QA. Before the deployment all my scripts were executing very fastly. But after deployment, the object identification is very slow and it is taking lots of time to perform the action. because of this the script execution is getting TimedOut. The new thing the developers have come up in this deployment is they have implemented Webresource.axd  technology. I am suspecting that the new technology is causing the slowness in object identification. But not very much sure about it.

    If I execute the Same Scripts in other environment in which the code is not yet deployed, it was working very fast.

    Need to confirn, do i have to change some Settings in VSTS 2010 or i need to do the modification in my coding. kindly suggest me with how can i resolve my Issues.

    pls help me out to resolve the issue.

    Thanks & Regards

    Kiran Dasari

  47. Hi Kiran – Clearly there is some change in the new deployment that is causing this.  Based on the information above, it is difficult to say what is that.

    You need to debug this further yourself and if you need help, I suggest posting on the forums mentioned above with logs to see if anyone in community can help you.


  48. Sandeep k says:

    Hi Goutham,

    The dll is not working for me, getting empty values for SYSLISTVIEW32 winlist item, could you help me in this?

    While doing automation, i wtore the code as below, just passed the "lst" winlist with search properties,

    but i am getting empty values, unable to read the SYSLISTVIEW32 winlistitem value.

    string[] strVal = CommonExtensions.GetValuesOfControls(lst.Items);

                   foreach (WinControl control in lst.Items)


                       int count = control.GetChildren().Count;

                       object objVal = CommonExtensions.GetValue(control);

                       WinListItem lstItem = (WinListItem)objVal;


                   foreach (WinControl control in lst.Items)


                       WinListItem listItem = new WinListItem(control);

                       string[] strSubItems = WinExtensions.GetColumnValues(listItem);


                   string[] ss = lst.GetColumnNames();

                   string[] colval = userlists.GetColumnValues();

    i am getting the objects as below,

    <AndCondition Id="SearchCondition">

    <PropertyCondition Name="ControlType">ListItem</PropertyCondition>

    <PropertyCondition Name="Instance">3</PropertyCondition>


    <AndCondition Id="SearchCondition">

    <PropertyCondition Name="ControlType">List</PropertyCondition>


    Thank You,


  49. HeadHunter12 says:

    Thanks alot Gautam… this has saved my life 🙂

  50. @sandeep – it is difficult to comment much here.  You will have to debug it yourself.

  51. Sandeep k says:

    Hi Gautham,

    Thanks for the quick reply,

    I have already debug the code,  it is giving only the grid column header names only.

    first i am working on Windows Applications, Coded UI is able to record the buttons, text boxes and all. But coming to the Grid which is having "SYSLISTVIEW32" – classname, the code ui is unable to get the Search Properties & Filter Properties for that control. it is just showing me just ControlType = ListItem, Instance=3 in the object repository.

    <UIObject ControlType="ListItem" Id="UIItemListItem" FriendlyName="" SpecialControlType="None">



                       <WindowTitle>TITLE XXXXXXX</WindowTitle>


                     <AndCondition Id="SearchCondition">

                       <PropertyCondition Name="ControlType">ListItem</PropertyCondition>

                       <PropertyCondition Name="Instance">3</PropertyCondition>



                     <Descendants />


    could you hellp me on this.

    Thank You,


  52. Quality Engineer S.S says:

    when using the Coded UI Testing , it couldn't read the name of controls in the splash screen it displayed as 'Unknown control '

    So , is there any solution for this issue

    please I need the reply ASAP

    thanks all

  53. Nitisha says:

    Hi Gautam,

       How do I reference these utilities in my project to be able to use them?

  54. Gautam,

    I see an error message "System.InvalidOperationException: The control passed is not a list view control.  This operation is valid only for list view control" when I do the following

               WinList list = new WinList(myWindow);

               string[] headers = list.GetColumnNames();

    However if I change my code as follows it works perfectly fine.

               WinList list = new WinList(myWindow);

               WinListItem listItem = new WinListItem(list);

               WinList listView = listItem.GetParent() as WinList;

               string[] headers = listView.GetColumnNames();

    This could be a possible bug. Or is it supposed to behave that way?

    Thanks for the DLL, hope this is included in the next official release.


  55. @Sandeep – I still cannot figure much here.  Please post on forums.

  56. @Quality Engineer S.S – It is difficult to say what could be wrong.  The unknown error typically comes when there is poor accessibility support.  Please try coded UI test forum.

  57. @Nitisha – In VS, you can use Add Reference to add the reference to the binary.

  58. @Madhu – Yes, part of these is being moved into the product.  I am not sure what the issue here is – suggest you contact someone via forum.

  59. Take says:

    The above mentioned Zip file is not available for download. Its been removed.

    Please suggest where can I get the downloadable Zip ?

  60. @Take – Which zip are you trying?  I am able to download this –…/

  61. searching corrospending values in different columns of the same row. says:

    I have a HtmlTable containing 11 columns and Rows( dynamic number).

    i need to get the value of  a cell in column 5  depending on value of column 6 of the same row.

    how do i first find the row in which Search value is reciding in column 6 and then pick up the value in the cell of same row of column 5.

    pl. let me know.

  62. What am I missing says:

    I'm trying to use this utility but I'm getting build errors so I'm missing something.  I've added the refence to the .dll as mentioned here but I'm getting the following build error : "Error 1 The type 'mshtml.IHTMLCurrentStyle' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'


    Error 2 The type or namespace name 'UITestingUtilities' could not be found (are you missing a using directive or an assembly reference?)

  63. You can easily get cell by row and column index without using this library.

  64. For error 1, add a reference to the Microsoft.mshtml assembly.  Coded UI Test also adds this but probably you may have deleted it.

    For error 2, ensure UITestingUtilities is deployed in the same folder as the test binary.  One easy way to do this is to do F4 on the reference and then in properties window of VS, set Copy Local to True.