How do you handle alerts and popups in Selenium?

Switch to alert using:

Alert alert = driver.switchTo().alert();
alert.accept(); // To accept the alert
alert.dismiss(); // To dismiss the alert

No images available.