Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click confirm navigation box with protractor

Tags:

protractor

I am running multiple cases using --suites config in protractor. I have to launch my webapp newly for each case but my app is having an alert which will be pop out for the confirmation [Stay on this page or Leave the page] whenever the page reloads or closed. In that case protractor throws an error

WARN - Exception: unexpected alert open:

Thanks in advance.

like image 588
I.P Avatar asked Oct 27 '25 14:10

I.P


2 Answers

Switch to the alert and accept it:

browser.switchTo().alert().accept();

This though might not work in Chrome, in this case you can do:

browser.executeScript("window.onbeforeunload = function(e){};");
like image 50
alecxe Avatar answered Oct 30 '25 15:10

alecxe


No of the found solutions had worked for me until I found a snippet in a Protractor thread. This:

browser.get(url).catch(function () {
    return browser.switchTo().alert().then(function (alert) {
        alert.accept();
        return browser.get(url);
    });
});

I hope this solution works for someone who, like me, was already desperate :P

like image 45
Filipe Melo Avatar answered Oct 30 '25 13:10

Filipe Melo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!