0

Why isn't it possible (using the InternetExplorerDriver) to accept alerts which have been triggered by explicitly executing JavaScript?

driver.ExecuteJavaScript("myfuncTriggeringAnAlert()");

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var alert = wait.Until(ExpectedConditions.AlertIsPresent());
alert.Accept();

The code works great using ChromeDriver, unfortunately however, the InternetExplorerDriver does not even return from the ExecuteJavaScript() call. It simply times out after 60 seconds.

Any ideas? Is this well-known behavior?

IE11 + IE Driver 2.48.0

D.R.
  • 20,268
  • 21
  • 102
  • 205
  • (same behavior with IE Driver 3.0) – D.R. Nov 30 '16 at 08:25
  • Yes, there are few bugs in handling alerts/prompts/confirms with `IE Driver`...actually with `chromedriver` also :) – Andersson Nov 30 '16 at 12:01
  • Oh... I missed one detail :) You skipped switching to alert! `wait.Until(ExpectedConditions.AlertIsPresent());` doesn't allow you to to accept alert: you need something like `alert.switch_to_alert()` (`Python` syntax) or `alert.switchTo().alert();` (`Java` syntax)... sorry, I can't recognize your programming language, also you didn't add appropriate tag – Andersson Nov 30 '16 at 13:00

1 Answers1

0

I think the problem is the window.alert function of JavaScript. It does not behave the same way in Internet Explorer than in other browsers. Selenium WebDriver is not able to handle it properly, for the best of my knowledge the only thing you can do is closing it manually in IE.

So, I would change your function myfuncTriggeringAnAlert to avoid to use native alerts. Maybe you can use a custom alert dialog, for example here.

Community
  • 1
  • 1
Boni García
  • 4,618
  • 5
  • 28
  • 44
  • Actually, in general one can accept alert triggered by `window.alert()` with `IE Driver`, but in some cases issues could occur – Andersson Nov 30 '16 at 13:03
  • Unfortunately, we cannot change to another alert library and have to stick to native alerts. We are now manually testing the alert behavior in IE instead of using Selenium :-( – D.R. Feb 12 '17 at 14:37