Python and Selenium - Disable all alerts -
using python 3 , selenium > chromedriver.
i running python script scrape stuff different web sites.
i need open , close lot of different sites.
problem:
my program crashes when alert fired.
selenium.common.exceptions.unexpectedalertpresentexception: alert text: none message: unexpected alert open
what trying fix situation?
when driver.get(), run:
driver.execute_script("window.alert = null;") driver.execute_script("window.prototype.alert = null;")
right before doing driver.close(), run:
driver.execute_script("window.onbeforeunload = null;")
right after doing driver.close(), do:
from selenium.common.exceptions import noalertpresentexception ... driver.close() # alert asking me if want close? try: driver.switch_to.alert.accept() except noalertpresentexception: pass
what achieving?
nothing, program keeps crashing:
question:
how may set whole thing, disable every alert.
if not possible, how may accept them or @ least program keeps flowing?
this has been asked lot of times, have done research prior asking question?
this should along, it's taken website mentioned below
public static void main(string[] args) { webdriver driver = new firefoxdriver(); driver.get("http://toolsqa.wpengine.com/handling-alerts-using-selenium-webdriver/"); driver.manage().window().maximize(); // step result in alert on screen driver.findelement(by.xpath("//*[@id='content']/p[4]/button")).click(); alert simplealert = driver.switchto().alert(); string alerttext = simplealert.gettext(); system.out.println("alert text " + alerttext); simplealert.accept(); }
Comments
Post a Comment