browser.switchTo().alert() not working in protractor.
sample code:
browser.get('');
browser.switchTo().alert().accept();
Message:
UnexpectedAlertOpenError: unexpected alert open
(Session info: chrome=39.0.2171.95)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)
Stacktrace:
UnexpectedAlertOpenError: unexpected alert open
C:\Users\Vikas.Gahlaut\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
UnexpectedAlertOpenError: unexpected alert open
Tried everything and it is not related to chrome driver issue as same is working fine with webdriver-java native APIs.
browser.switchTo().alert() not working in protractor.
sample code:
browser.get('http://google.');
browser.switchTo().alert().accept();
Message:
UnexpectedAlertOpenError: unexpected alert open
(Session info: chrome=39.0.2171.95)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)
Stacktrace:
UnexpectedAlertOpenError: unexpected alert open
C:\Users\Vikas.Gahlaut\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
UnexpectedAlertOpenError: unexpected alert open
Tried everything and it is not related to chrome driver issue as same is working fine with webdriver-java native APIs.
Share Improve this question edited Jan 14, 2015 at 11:39 Vivek Singh 3,6492 gold badges24 silver badges28 bronze badges asked Jan 14, 2015 at 11:10 Vikas GahlautVikas Gahlaut 412 silver badges8 bronze badges 2- Are you sure there is an alert opened? – alecxe Commented Jan 14, 2015 at 12:34
- Yes alecxe,It's an alert as I am able to handle it using webdriver's API, driver.switchTo().alert().accept() but not with protractor and the error also says unexpected alert open – Vikas Gahlaut Commented Jan 14, 2015 at 18:27
4 Answers
Reset to default 4Unless you've set ignoreSynchronization
, the fact that you're navigating to a non angular app (google.) is messing it up.
Try
browser.driver.get('http://google.');
browser.switchTo().alert().accept();
or
browser.ignoreSynchronization = true
browser.get('http://google.');
browser.switchTo().alert().accept();
Sometimes the alert takes a time until it appears, you can try adding a wait before you make an accept:
browser.ignoreSynchronization = true
browser.get('http://google.');
browser.wait(protractor.ExpectedConditions.alertIsPresent(), 10000);
browser.switchTo().alert().accept();
This is what I did, so that it does not fail if no alert is open:
browser.ignoreSynchronization = true;
browser.get('http://google.');
browser.switchTo().alert().then(function() {
browser.switchTo().alert().accept();
}, function(){});
browser.ignoreSynchronization = false;
browser.get("your.address.");
browser.switchTo().alert().then(function(alert) {
alert.accept();
}).catch(function(error) {
});