use js to give response to alert code example
Example 1: how to send an alert in javascript
function mousePressed() {
alert("I'm the best");
}
function keyPressed() {
if (keyCode === UP_ARROW) {
alert(number = random(0, 500));
}
}
if(x > width) {
alert("yay you did it");
}
Example 2: 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();