瀏覽代碼

report error if element is not displayed

Rodja Trappe 2 年之前
父節點
當前提交
6143e8095e
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      tests/screen.py

+ 4 - 1
tests/screen.py

@@ -93,7 +93,10 @@ class Screen:
     def find(self, text: str) -> WebElement:
         try:
             query = f'//*[not(self::script) and not(self::style) and contains(text(), "{text}")]'
-            return self.selenium.find_element(By.XPATH, query)
+            element = self.selenium.find_element(By.XPATH, query)
+            if not element.is_displayed():
+                raise AssertionError(f'Found "{text}" but it is hidden')
+            return element
         except NoSuchElementException:
             raise AssertionError(f'Could not find "{text}"')