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…