Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.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/selenium/4.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 将\u切换到\u alert.text()不工作_Python_Selenium - Fatal编程技术网

Python 将\u切换到\u alert.text()不工作

Python 将\u切换到\u alert.text()不工作,python,selenium,Python,Selenium,我在python中使用SeleniumWebDriver来抓取弹出窗口的内容。我使用driver.switch_到\u alert.text()来检索内容 当我调用驱动程序时,我得到了警报对象。切换到\u alert,但我无法使用对象的acccept()、dismise()和文本函数 如果我调用alert,我会得到对象 但是如果调用alert.text,我会得到以下错误 NoAlertPresentException Traceback (most rec

我在python中使用SeleniumWebDriver来抓取弹出窗口的内容。我使用
driver.switch_到\u alert.text()
来检索内容

当我调用
驱动程序时,我得到了警报对象。切换到\u alert
,但我无法使用对象的
acccept()
dismise()
和文本函数

如果我调用alert,我会得到对象

但是如果调用alert.text,我会得到以下错误

NoAlertPresentException                   
Traceback (most recent call last)
<ipython-input-162-7b8c4cd45721> in <module>()
----> 1 alert.text
C:\Users\\Anaconda\lib\site-packages\selenium\webdriver\common\alert.pyc in text(self)
     63         Gets the text of the Alert.
     64         """
---> 65         return self.driver.execute(Command.GET_ALERT_TEXT)["value"]
     66 
     67     def dismiss(self):
NoAlertPresentException
回溯(最近一次呼叫最后一次)
在()
---->1.text
C:\Users\\Anaconda\lib\site packages\selenium\webdriver\common\alert.pyc文本(self)
63获取警报的文本。
64         """
--->65返回self.driver.execute(Command.GET_ALERT_TEXT)[“value”]
66
67 def解雇(自我):
我尝试通过睡眠(5)延迟执行,但没有任何效果。

然后切换到:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

wait = WebDriverWait(driver, 10)
wait.until(EC.alert_is_present())

alert = driver.switch_to.alert
alert.accept()