VS2010 Coded UI Test - Test Generator unable to map two boxes with the same text


I'm trying to create a coded UI test (with VS2010 Ultimate) for a simple web form page with two checkboxes and a submit hyperlink. The checkboxes have the same text label; "I Agree".

  • Using the coded UI test builder to record actions, only one checkbox is captured because both checkboxes have the same text / same UIMap Name.
  • Using the crosshair tool to select the second checkbox, it replaces the previous checkbox instance because they have the same text / same UIMap Name.

When the test is run, the first checkbox is checked, the second is not, and the hyperlink is clicked to submitted the form (failing validation).

How can I add the second checkbox to the test map and differentiate between the two?

If there are no unique properties on the checkboxes themselves, specify the parent object of each checkbox to differentiate them.


<div id="box1Parent">
    <input label="I Agree"/>
<div id=box2Parent">
    <input label="I Agree"/>

You would define the object like this:

public HtmlCheckBox AgreementBox1()
    HtmlDiv parent = new HtmlDiv(browser);
    parent.SearchProperties["id"] = "box1Parent";
    HtmlCheckBox target = new HtmlCheckBox(parent);
    target.SearchProperties["label"] = "I Agree";
    return target;

Then, do the same for the second box, but point the parent to box2Parent. This would be your code in the non-designer section of the .uitest class.