尝试单击该元素,但总是有一个UnexpectedAlertPresentException.Adding 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"
答案 0 :(得分:1)
Selenium 2 switchin警报已更改。将您的命令更改为fox.switchTo().alert().accept();
答案 1 :(得分:1)
你可以试试..
try {
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
//exception handling
}