How to click OK in the warning window using the protractor

I am using AngularJS and I want to remove the link, in such cases a warning message appears confirming the removal.

I am trying to run an e2e test using a protractor, how can I confirm in the warning box?

I tried:

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

but it does not work.

Is there a condition in the protractor for handling warning boxes?

+5
source share
3 answers

Wait for the warning to appear :

 var EC = protractor.ExpectedConditions; browser.wait(EC.alertIsPresent(), 5000, "Alert is not getting present :(") 
+5
source

try

 browser.driver.get('URL'); browser.switchTo().alert().accept(); 

or

 browser.ignoreSynchronization = true browser.get('URL'); browser.switchTo().alert().accept(); 

or: browser.switchTo (). alert () does not work in the transporter

+3
source

Set up a promise to wait for an alert:

 function getAlertAndClose(element) { return element.click().then(function (alertText) { //Wait for alert to pop up browser.wait(function () { return browser.switchTo().alert().then( function () {return true;}, function () {return false;} ); }, 3000); // Wait timeout // Test alert is what you expect var popupAlert = browser.switchTo().alert(); alertText = popupAlert.getText(); expect(alertText).toMatch('Are you sure you want to delete this?'); // Close alert popupAlert.dismiss(); }) } var saveButton = $('.saveBtn'); getAlertAndClose(saveButton); 
0
source

All Articles