Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用Chrome在Selenium WebDriver中获取警报()框 简言之_Python_Selenium_Alert_Selenium Chromedriver - Fatal编程技术网

Python 无法使用Chrome在Selenium WebDriver中获取警报()框 简言之

Python 无法使用Chrome在Selenium WebDriver中获取警报()框 简言之,python,selenium,alert,selenium-chromedriver,Python,Selenium,Alert,Selenium Chromedriver,今天,我无法在这里获得使用SeleniumWebDriver从Python获取javascript alert()框的代码 全部 我对该主题的研究给了我很多结果,例如使用EC.alert\u is\u present()和driver.switch\u至\u alert() 我遵循这一点,在github上编写了一个简单的代码,试图从Python代码访问alert对象。尽管我失败了,超时异常如下,即webdriver无法获取alert()box对象 Traceback (most recent c

今天,我无法在这里获得使用SeleniumWebDriver从Python获取javascript alert()框的代码

全部 我对该主题的研究给了我很多结果,例如使用
EC.alert\u is\u present()
driver.switch\u至\u alert()

我遵循这一点,在github上编写了一个简单的代码,试图从Python代码访问alert对象。尽管我失败了,超时异常如下,即webdriver无法获取alert()box对象

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: 
回溯(最近一次呼叫最后一次):
文件“util/sandbox/my_sandbox/test_alert_box.py”,第49行,在
WebDriverWait(驱动程序,10).直到(EC.alert_存在())#TODO为什么警报框不可用?我们这里有错误
文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/wait.py”,第80行,直到
引发TimeoutException(消息、屏幕、堆栈跟踪)
selenium.common.Exception.TimeoutException:消息:

所以,如果你知道如何让它工作,请分享。谢谢大家!

我没有使用python,这只是一个想法。您可以尝试在try/catch块内执行webdriver wait吗?在启动webdriver-->驱动程序后,还可以尝试使用隐式等待。隐式等待(10)#secondsThanks@santhoshkumar。请您澄清一下try/catch是如何起作用的-我想它只是关闭了异常,但事实是我们无法获取alert()框。我已经尝试了
驱动程序。隐式地等待(10)
,但仍然得到超时异常。我同意您关于try-catch块的问题。我知道这很奇怪,但有时对我有用。同样,这只是一个尝试的想法。它在我的机器上运行良好。若要检查警报是否发出,请在单击“重试”按钮后添加一些使用时间。睡眠(10)。我可以看到警报对话框。我没有使用python,这只是一个想法。您可以尝试在try/catch块内执行webdriver wait吗?在启动webdriver-->驱动程序后,还可以尝试使用隐式等待。隐式等待(10)#secondsThanks@santhoshkumar。请您澄清一下try/catch是如何起作用的-我想它只是关闭了异常,但事实是我们无法获取alert()框。我已经尝试了
驱动程序。隐式地等待(10)
,但仍然得到超时异常。我同意您关于try-catch块的问题。我知道这很奇怪,但有时对我有用。同样,这只是一个尝试的想法。它在我的机器上运行良好。若要检查警报是否发出,请在单击“重试”按钮后添加一些使用时间。睡眠(10)。我可以看到警报对话框。
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: