尝试单击该元素,但始终有一个 UnexpectedAlertPresentException。将 UnexpectedAlertPresentException 添加到代码中不会改变任何东西,因为未单击该元素并且未出现弹出窗口。我认为可能是由于弹出窗口没有太多时间出现,但它没有帮助太。 事件尝试通过功能接受所有弹出窗口...
cap = DesiredCapabilities.FIREFOX
cap["UnexpectedAlertPresentException"] = "accept"
fox = webdriver.Firefox(capabilities=cap)
fox.find_element_by_link_text("My Account").click()
try:
WebDriverWait(fox, 3).until(EC.alert_is_present(),
'Timed out waiting for PA creation ' +
'confirmation popup to appear.')
fox.switch_to.alert().accept()
print "alert accepted"
except TimeoutException:
print "no alert"
请您参考如下方法:
你可以试试..
try {
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
//exception handling
}
