如何在Selenium-Python中获取小吃店警报的文本?

时间:2019-06-26 10:54:13

标签: selenium-webdriver python-3.7

我正在自动执行角材应用程序,并且我们使用小吃店发出警报。我无法从小吃店获取文本,因为switch_to.alert方法不起作用。在这里并给出错误

driver.find_element_by_xpath("//span[@class='mat-option-text'][contains(.,'Bhopal')]").click()
    driver.find_element_by_xpath("//button[@class='mat-raised-button mat-primary']").click()
    button = driver.find_element_by_xpath("//mat-label[contains(text(),'Users')]").click()
    active = driver.switch_to.alert
    a = active.text
    print(a)

raceback (most recent call last):
  File "C:/Users/FizaQ/PycharmProjects/HMS/test_data_driven.py", line 38, in <module>
    active = driver.switch_to.alert
  File "C:\Users\FizaQ\PycharmProjects\HMS\venv\lib\site-packages\selenium\webdriver\remote\switch_to.py", line 55, in alert
    alert.text
  File "C:\Users\FizaQ\PycharmProjects\HMS\venv\lib\site-packages\selenium\webdriver\common\alert.py", line 69, in text
    return self.driver.execute(Command.GET_ALERT_TEXT)["value"]
  File "C:\Users\FizaQ\PycharmProjects\HMS\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\FizaQ\PycharmProjects\HMS\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
  (Session info: chrome=75.0.3770.100)
  (Driver info: chromedriver=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Windows NT 10.0.17134 x86_64)

0 个答案:

没有答案