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”;
pop.DrawHighlight();

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);
}
else
{
Console.WriteLine(“System is displaying ” + msg);
}

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

Advertisements

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(“http://www.google.com”));

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

Mouse.Click(newwindow);

Hope it will help…