简体   繁体   中英

How do I ignore an alert using selenium + chrome webdriver + python?

I need to ignore the alert raised by Chrome Webdriver: Alert Screenshot

I am trying using: browser.switch_to.alert.accept but it is not working.

I already set up the option as:

chrome_options = Options()
chrome_options.add_argument("--disable-notifications")

But I believe the alert is not a notification object.

Thank you for your help!

Have you tried this.

chrome_options = Options()
chrome_options.add_argument("--disable-popup-blocking")

While your original post mentioned that you couldn't get the alert code to work, the accepted answer didn't work for me. Looking at the documentation , I successfully used:

 alert = browser.switch_to.alert
 alert.accept()

This way helped me to handle the alert boxes and save the screenshot of the URL.

Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
System.out.println("ERROR: (ALERT BOX DETECTED) - ALERT MSG : " + alertText);
alert.accept();
File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String imageDetails = "C:\\Images";
File screenShot = new File(imageDetails).getAbsoluteFile();
FileUtils.copyFile(outputFile, screenShot);
System.out.println("Screenshot saved: {}" + imageDetails);
driver.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM