How to verify availability of options in a Drop-Down field with CodedUI (C#)

It’s easy to get to know if particular option is available in drop-down field, as we just select that option and it verifies that…OK option is available. However if we want to verify that particular option is not available in some drop-down field then we need to think about some trick. One of trick is given below to get to know that option is not available-

public Boolean CheckOption(browser, String DropDownObjectID, String Option)
HtmlComboBox SelectObject = new HtmlComboBox(browser);
SelectObject.SearchProperties.Add(“Id”, DropDownObjectID);
String[] Selectoption = SelectObject.GetContent();
Boolean result = false;
foreach (String data in Selectoption)

if (data.Contains(Option))

return result;


How to identify HtmlTag.A object with CodedUI (C#)

I invested many hours to find out that how we can identify class: ‘HtmlTag.A’ object? Eventually I have found that we can use ‘HtmlCustom’ class to identify ‘HtmlTag.A’ object. Below syntax will help to find it and click on it-

HtmlCustom Tab = new HtmlCustom(browser);
Tab.SearchProperties.Add(“InnerText”, “ManageUser”, “TagName”, “A”);

Provide your comment if it is not working in your case.

How to select date from calendar in CodedUI (C#)

If you have calendar which have Month and Year drop-downs and date in tags then follow below code to select the date from the calendar


HtmlImage calImage = new HtmlImage(browser);
cal.SearchProperties.Add(“Id”, “ImageID”); //It finds the ‘V’ image of calendar to open.
Mouse.Click(cal); //It opens the calender.
HtmlComboBox Month = new HtmlComboBox (browser);
Month.SearchProperties.Add(“Id”, “MonthDropDownID”); //It finds the Month drop-down field.
Month.SetProperty(“SelectedItem”, “December”); //It selects provided Month in drop-down field.
HtmlComboBox Year = new HtmlComboBox (browser);
Year.SearchProperties.Add(“Id”, “YearDropDownID”); //It finds the Year drop-down field.
Year.SetProperty(“SelectedItem”, “2015”); //It selects provided Year in drop-down field.
HtmlTable Calender = new HtmlTable(browser);
Calender.SearchProperties.Add(“Id”, “CalenderTableID”); //It finds the Calender table.
HtmlCell date = new HtmlCell(Cal);
date.SearchProperties.Add(“InnerText”, “31”); //It find provided date by InnerText.
Mouse.Click(date); //It selects provided Date from the Calender.

How to select drop-down value in CodedUI (C#)

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();

How to handle IE Alert pop-up with CodedUI (C#)

Below code will help to handle IE Alert pop-up-

HtmlButton Submit = new HtmlButton (browser);

Mouse.Click (Submit);

WinWindow pop = new WinWindow(null);
pop.SearchProperties.Add(“Name”, “Message from webpage”, “ClassName”, “#32770″);
pop.TechnologyName = “MSAA”;

WinText text = new WinText(pop);

text.SearchProperties.Add(“Name”, “Some Name”);
String msg = text.GetProperty(“DisplayText”).ToString();

if (msg.Contains(“Data saved.”))

Console.WriteLine(“System is displaying ” + msg);
Console.WriteLine(“System is displaying ” + msg);

WinButton ok = new WinButton(pop);
ok.TechnologyName = “MSAA”;
ok.SearchProperties.Add(“Name”, “OK”);

How to close browser window in CodedUI (C#)

It is very small action but if you are new with CodedUI and struggling to take off (Opening and Closing the browser) with CodedUI then this post could help you…

To start browser and your application you can use below line of code-

BrowserWindow browser = BrowserWindow.Launch(new System.Uri(“”));

Above code will start you browser.

browser.close(); //it will close your browser.

If you have switched to new window and now if you wanted to close only that window then use below code sample-

BrowserWindow newwindow = new BrowserWindow();
newwindow.SearchProperties.Add(“Title”, “Google”);


Hope it will help…

How to simulate keyboard input in C# (CodedUI)

In my initial days, I have struggled lot to simulate keyboard inputs. To simulate keyboard inputs in CodedUI as easy as Selenium but sometime it’s hard to find CodedUI solution over the Google. With this post I am trying to break that hardness. So here we go…

if you wanted to send single key…



Keyboard.SendKeys(“{T}”); etc.

If you wanted to send combination keys like ALT+F4.


Code     Key

%          ALT

+           SHIFT

^           CTRL

If you wanted to press particular key 10 times, use below syntax-

//Below syntax will press LEFT ARROW key 10 times.

Keyboard.SendKeys(“{LEFT 10}”);

For more details you can go through this link