Monday 21 November 2011

How to handle Prompts in selenium webdriver using CSharp

Here when we click on the below element it's asking for the name.

driver.FindElement(By.XPath("//input[@value='I dare you to click me!']")).Click();
IAlert alert = driver.SwitchTo().Alert();              //Switch to Alert
IWebElement name = driver.SwitchTo().ActiveElement();  // Switch driver to Active Element
name.SendKeys("anjaneyulu");
alert.Accept();
IAlert alert2 = driver.SwitchTo().Alert();
string text = alert2.Text;
Console.WriteLine(text);
alert2.Accept();

1 comment:

  1. Please this code doesn't work for native widows prompt.. please can you provide similar step by step on how you can authenticate on a Windows prompt.. thank you

    ReplyDelete