How to click javascript confirm dialogue box with selenium webdriver in C# How to click javascript confirm dialogue box with selenium webdriver in C# selenium selenium

How to click javascript confirm dialogue box with selenium webdriver in C#


I don't know why your code was not working(my be version specific), Its working fine for me.

IAlert alert = driver.SwitchTo().Alert();alert.Accept();

Any ways, you can do this way also,

SendKeys.SendWait("{ENTER}");

but before doing this make sure "System.Windows.Forms.dll" is added in your project References and also make sure your app is active when running, mean don't click on other window when popup appears and don't let your computer to be sleep.


It is ugly but... what I do I force the enter key for alerts and confirms


If the dialog is disappearing from the screen. It means the Alert is getting Suppressed. You can use the Following Code:

DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();ieCapabilities.setCapability("unexpectedAlertBehaviour", "ignore");WebDriver driver = new InternetExplorerDriver(ieCapabilities);