Python 将\u切换到\u alert.text()不工作
我在python中使用SeleniumWebDriver来抓取弹出窗口的内容。我使用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
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()