-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnexpectedAlertOpenError #308
Comments
There's an example of closing an alert here: https://github.com/angular/protractor/blob/master/spec/basic/actions_spec.js#L18 Since you will sometimes have an alert and sometimes not, you may need to handle promise errors for the situation when there is not an alert. |
Seems like this is resolved, closing for tidiness. Please open a new issue or pull request if there is still an issue. |
Hi julie, we are running protractor tests locally triggered by Jenkins on a build server. Are there any other way to handle somewhat unexpected alerts more generally? Kind of annoying that the browser will stay open and all of the remaining tests will crash after the alert appeared. I think its generally a bad practice to handle errors with alerts, but unfortunately we have implemented that temporarily so it would be great if there had been a setting to just omit alerts and just fail the test. |
I suppose you could do a try/catch block and look for |
Hi, I have been fighting recently with this behaviour. I finally solved this using the webdriver Error Handling propagation. Something similar to this:
More documentation and examples about this can be found on the WebdriverJS User's Guide (search for a "alert()" text and you will find the solution): |
Also having this issue- seems to sometimes work and sometimes not for me. I have a page where if a user tries to navigate away without saving changes, an alert pops up. I'd like to dismiss this alert. Here is the code: ...
# Navigate away from the page
browser.get "/home"
# But, there are unsaved changes, so an alert pops up
# Dismiss the alert
browser.switchTo().alert().then (alert) ->
alert.accept() But the code fails to dismiss the alert: UnexpectedAlertOpenError: unexpected alert open Any ideas? |
Looks like the issue is that the dialog isn't an alert per se- it's triggered with a Did some Googling on the issue, but still unable to get it to close properly. There are hacky ways of getting around it, like this: browser.executeScript "window.onbeforeunload = function(){};" But I'd like the right way of doing it. Has anyone solved this issue? |
In my case I would like to catch |
Anyone have any luck with this? |
Having a similar issue. Previously |
Also tried this solution which doesn't work for me:
|
I am still unable to use browser.switchTo().alert(); Tried everything and it is not related to chrome driver issue as same is working fine with webdriver-java native APIs. This is blocking usage of protractor and I am afraid I need to revert to webdriver - java API. Please update any luck on this?? |
Having the same issue here. Hacky workaround:
Above will close the onbeforenload created dialog, but obviously precludes the ability to test any associated logic and/or behavior related to it. Are there any updates on this issue or if/when it will be resolved? |
Unfortunately, the hack above in #308 (comment) is not working for me. I have another hack that seems to be working: browser.executeScript( "window.angular.element(window).off('beforeunload');" ); |
For anyone who's still struggling, this seems to be a proper solution: browser.get(url).catch(function () {
return browser.switchTo().alert().then(function (alert) {
alert.accept();
return browser.get(url);
});
}); |
Thanks @fyodorvi ! Your solution works. |
I can confirm @fyodorvi solution works. This ticket should be closed.
|
How to handle alerts in the application when we are not sure when alerts will come, for intermittent errors/alerts. |
@Sankannavar that's really the point of testing though is that these are known routes with set-out test criteria that give expected and predictable results. If your application is throwing up a whole bunch of "random" alerts your application isn't working correctly. |
@inthegarage Thanks for information. |
For anyone who's still struggling, I have another solution which worked for me browser
.switchTo()
.window(windowHandle)
.then(() => {
browser
.refresh()
.then(() => {
console.log("success referesh");
})
.catch(err => {
browser
.switchTo()
.alert()
.then(alert => {
browser.sleep(5000);
alert.accept();
browser.sleep(5000);
});
});
});
});``` |
My web app calls alert on startup if the user is using an old version of IE such as IE8. I need my Protractor test to dismiss that alert. Just attempting to access it throws an UnexpectedAlertOpenError. Here is the line of code.
var dialog = ptor.switchTo().alert();
I was hoping after getting a reference to it, I could close it.
The text was updated successfully, but these errors were encountered: