Handling Alert in Selenium WebDriver (Selenium 2)

前端 未结 7 1271
后悔当初
后悔当初 2020-12-16 04:26
driver.findElement(By.xpath(\"//input[@value=\'添加\']\")).click(); 
//Pops out an Alert and program stops, does not continue 

how to click the alert

7条回答
  •  执笔经年
    2020-12-16 04:50

    Alert alert = driver.switchTo().alert();
    alert.accept();
    

    If you want to cancel the pop up use the following:

     alert.dismiss();
    

    instead of

     alert.accept():
    

提交回复
热议问题