Selenium NoAlertPresentException -


i'm trying handle dialog (ok cancel type) selenium webdriver. aim click "ok" button.

scenario is:

  1. click button invoking dialog

    button.click();

  2. try accept

    webdriver.switchto().alert().accept();

but i'm getting noalertpresentexception , seeing dialog closes immediately. seems me selenium automatically closes dialog , when want accept, there nothing accept.

i'm sorry bad english.

the usual cause of issue selenium quick , tries accept alert has not yet been opened browser. can fixed explicit wait:

button.click(); webdriverwait wait = new webdriverwait(driver, 5); alert alert = wait.until(expectedconditions.alertispresent()); alert.accept(); 

Comments