Cannot get alert() box in Selenium WebDriver with Chrome

安稳与你 提交于 2020-01-07 04:25:09

问题


In brief

Today I cannot get my code here 00 01 works to get javascript alert() box from Python with Selenium WebDriver.

In full

My google search on the topic gave me many results e.g. this one using EC.alert_is_present() and driver.switch_to_alert()

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("...some page...")
WebDriverWait(driver, 5).until(EC.alert_is_present())
driver.switch_to_alert().accept()

I follow that and write a simple code on my github here 00 01 trying to access the alert object from Python code. Though I failed with the timeout exception as below i.e. the webdriver cannot get the alert() box object.

Traceback (most recent call last):
  File "util/sandbox/my_sandbox/test_alert_box.py", line 49, in <module>
    WebDriverWait(driver,10).until(EC.alert_is_present()) #TODO Why alert box not available? We got error here
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

So if you know how to get it work, please share. Thank you!

来源:https://stackoverflow.com/questions/44650624/cannot-get-alert-box-in-selenium-webdriver-with-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!