Below code will help to select values in drop-down field-

HtmlComboBox State = new HtmlComboBox(browser);
State.SearchProperties.Add(“Id”, “State”);
State.SetProperty(“SelectedItem”, “Assam”);

State.SetProperty(“SelectedItem”, “Goa”);

If you want to get by default selected value from Drop-Down field then use below method to get that-

String Default=State.SelectedItem.ToString();


25 thoughts on “How to select drop-down value in CodedUI (C#)

      1. I am having a Read only Textbox. By clicking, it opens a calendar and we can pick a date from that only but can not enter in textbox manually. I have to write the code for it because Recording even does not work. And Setproperty also does not work. Please help me for the same. Thanks!!

    1. Please WinWindow class to handle windows object. As I am guessing you have browse button and once you click on that it suggest to choose the file some location.

  1. Yeah sure, you can ping me or comment over here for any suggestion or help. Try your best you can resolve the issue. Just open the table and take all ‘tr’ and ‘td’. I am guessing all the dates are ‘a’ hyperlink object so you can click on any date with HtmlHyperlink class also. Its just a hint just see if you can resolve.

    1. HtmlTable Calender = new HtmlTable(browser); Calender.SearchProperties.Add(“Id”,”ctl00_Main_MyLeave1_txtTo0_CalendarExtender_daysTable”);
      HtmlCell date = new HtmlCell(Calender);
      date.SearchProperties.Add(“InnerText”, “17”);
      date.SearchProperties.Add(“Id”, “ctl00_Main_MyLeave1_txtTo0_CalendarExtender_day_2_3”);

      I have tried above code and date is highlighted but it gives error on throwing exception “Failed to find control. Please make hidden control visible”.

  2. Hi Pooja,

    Hope below code would solve your problem-

    HtmlEdit cal = new HtmlEdit(browser);
    cal.SearchProperties.Add(“Id”, “CalTextID”);

    HtmlTable calender = new HtmlTable(browser);
    calender.SearchProperties.Add(“Class”, “ui-datepicker-calendar”);
    HtmlCell Cell = new HtmlCell(calender);
    Cell.FilterProperties[HtmlCell.PropertyNames.RowIndex] = 1.ToString();
    Cell.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = 2.ToString();
    HtmlHyperlink date= new HtmlHyperlink(Cell);
    date.SearchProperties.Add(“InnerText”, “2”);

    1. This too does not work. It shows failed to find Hyperlink even if proper date is given and its properly highlighted. And if i try without using hyperlink and clicking on Cell directly then too it highlights proper cell but does not work on saying failed to find hidden control.

      1. Not Actually. While running recorded method, it selects some another date and not the one selected at the time of Recording. So it does not work as expected through Test builder also.

      2. However in any case we need object properties for the calender objects. Just find out some way to get the properties otherwise it would be difficult to automate.

      3. Yes I will try if i can get.For now, I am switched to Selenium Webdriver and it works fine with it. I will let you know if i get the properties. Thanks a lot for your help!!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s