How to cancel and accept Alert in Protractor?

Eunice Ache
Eunice Ache

Posted On: Jan 11, 2021


You can cancel Alert in Protractor by using dismiss() as follows:

The dismiss() method is used to cancel the alert for handling alerts in Selenium. It is functional for all alert types: prompt, alert, and confirmation dialogue box.

It activates by clicking on the “X” button in the prompt. 

You can accept Alert in Protractor by using accept() as follows:

The accept() method is used to accept an alert and continue with the webpage operation. It can be utilized for all JavaScript alert types. An alert command can be executed by using the variable for handling alerts in Selenium:

var myAlert = browser.switchTo().alert();
Click on the 'OK' button will confirm the action

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Protractor Interview Questions

    How to use Cucumber with Protractor?

    To use Cucumber. js, you should update the framework and add a framework path, and then add a few cucumberOpts that specify where to find the step definition files such that it will now run the protra...

    Protractor Interview Questions

    What is difference between WebDriver click() and JavaScript click()?

    WebbDriver click() simulates real user interaction with the UI whereas JavaScript click() executes JavaScript in the currently selected frame or window....

    Protractor Interview Questions

    How to select an option from dropdown in Protractor e2e testing?

    You can select an option from the dropdown in Protractor e2e testing with the following step:Find the dropdown using the element. Click the dropdown. Click the option. ...