How do you handle js alerts? code example

Example 1: javascript alert

alert("string");

Example 2: java script alerts

- Information : You can only accept.
            - Confirmation: You can accept or decline.
            - Prompt    : You can accept, decline, and/or sendKeys.

Example 3: How do you handle js alerts?

If the alert on the browser comes from JavaScript, we use to
handle them Alert class.
Alert alert = driver.switchTo.alert();
alert.accept();
alert.dismiss();
alert.sendKeys();
alert.getText();

Example 4: js alerts

3 types of JS Alerts

            - Information : You can only accept.
            - Confirmation: You can accept or decline.
            - Prompt    : You can accept, decline, and/or sendKeys.

Tags:

Java Example