由于弹出窗口无法单击该元素

Can't click the element due to popup

尝试点击该元素,但总是有一个 UnexpectedAlertPresentException.Adding 代码的 UnexpectedAlertPresentException 不要改变任何东西,因为元素没有被点击并且弹出窗口不是 appeard.I 认为可能是由于弹出窗口没有太多是时候出现了,但它也没有帮助。 事件尝试通过功能接受所有弹出窗口...

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"

Selenium 2 切换警报已更改。将命令更改为 fox.switchTo().alert().accept();

你可以试试..

try {
    WebDriverWait wait = new WebDriverWait(driver, 2);
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    alert.accept();
} catch (Exception e) {
    //exception handling
}