如何使用 Selenium (Python) 在网页中查找 'alert-warning'

How to find 'alert-warning' in web page with Selenium (Python)

我有这个 HTML 代码:

<button ng-show="vm.loading_update" class="alert alert-warning">
  <strong>Upgrading firmware... Please Wait...</strong>
</button>

单击上一个按钮时会打开此警告消息(这没问题)。 所以,我有这个小代码但不起作用,找不到警报消息。

self.elem = self.driver.find_element_by_xpath('//button[text()="Upgrade"]')
self.elem.click()
time.sleep(1)

WebDriverWait(self.driver, 2).until(EC.alert_is_present(),
                                     "Upgrading firmware... Please Wait...")
alert_test = self.driver.switch_to.alert()
alert_test.accept()

我需要知道是否显示此消息才能继续测试...

提前致谢。

使用以下代码:

try:

    WebDriverWait(self.driver, 2).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".alert.alert-warning>strong")))

except:

    print("The alert is not displayed!")