How to select drop down/combo list item?

Jun 29, 2012 at 6:21 PM

I just started using CUITe, have gotten the hang of accessing object repository pages.

On one page, there are drop down lists (recorded as HtmlEdit) and drop down checkbox lists (recorded as HtmlCheckBox).

How can I select a specific value from a drop down list, or check one or more values within a dropdown multi-select checkbox list?

Coordinator
Jun 29, 2012 at 6:42 PM

Hi Mark,

Do you have an example html page with these controls?

There is sample code in the form of unit tests in the Sample_CUITeTestProject project's source code.

From TestHtmlPage.html:

<select id="select1">
    <option>Cricket</option>
    <option>Football</option>
    <option>Tennis</option>
</select>

From Tests_for_HtmlControls.cs:

CUITe_BrowserWindow bWin = CUITe_BrowserWindow.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");
var cmb = bWin.Get<CUITe_HtmlComboBox>("Id=select1");
Assert.AreEqual("Football", cmb.Items[1]);
Assert.IsTrue(cmb.ItemExists("Cricket"));
bWin.Close();

 

The SelectItem method of CUITe_HtmlComboBox can be used to select an item.

However, there is no example on selecting multiple items.

The Coded UI Test Recorder can also be used to record user interactions with the browser and the generated code can then be applied using CUITe.

 

Thank you.

Oct 2, 2013 at 4:41 PM
This post really helped me. Thank you.

I was able to select an item from a combo box drop down by using the SelectItem method and passing in the index.
           //select insitutional
           enterprisetestsuite.Get<CUITe_HtmlComboBox>("Id=ClaimTypeOption").SelectItem(0); 
           //select professional
           enterprisetestsuite.Get<CUITe_HtmlComboBox>("Id=ClaimTypeOption").SelectItem(1);
I still want to explore options to make the test easier to read and have the selectitem use the string I am trying to select in the drop down instead of the index number.

Thanks again!
Oct 3, 2013 at 11:14 AM
Hi IanCeicys,

Have you used "public void SelectItem(string sItem)" method?

eg:
enterprisetestsuite.Get<CUITe_HtmlComboBox>("Id=ClaimTypeOption").SelectItem("value1");