如@DebanjanB所建议,在WebDriverWait starts
和WebDriverWait ends
消息之间清晰可见的弹出窗口可能不是警报。在这种情况下,我们如何按“允许”。
chrome_options = webdriver.ChromeOptions()
prefs = { "profile.default_content_setting_values.notifications" : 2 }
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=CHROME_DRIVER_PATH)
driver.get(url)
try:
print("WebDriverWait starts")
WebDriverWait(driver, 10).until(EC.alert_is_present(), 'Timed out waiting for PA creation confirmation popup to appear.')
alert = driver.switch_to.alert
alert.accept()
print("alert accepted")
except TimeoutException as e:
print("WebDriverWait ends: ", e)
pass
WebDriverWait启动
WebDriverWait结束:消息:等待PA创建确认弹出窗口超时。