Wait until the method returns a value that is not False. Calls the method provided with the driver as an argument until the return value does not evaluate to ``False``. Args: method: A callable object that takes a WebDriver instance as an argumen
(self, method: Callable[[D], Literal[False] | T], message: str = "")
| 76 | return f'<{type(self).__module__}.{type(self).__name__} (session="{self._driver.session_id}")>' |
| 77 | |
| 78 | def until(self, method: Callable[[D], Literal[False] | T], message: str = "") -> T: |
| 79 | """Wait until the method returns a value that is not False. |
| 80 | |
| 81 | Calls the method provided with the driver as an argument until the |
| 82 | return value does not evaluate to ``False``. |
| 83 | |
| 84 | Args: |
| 85 | method: A callable object that takes a WebDriver instance as an |
| 86 | argument. |
| 87 | message: Optional message for TimeoutException. |
| 88 | |
| 89 | Returns: |
| 90 | The result of the last call to `method`. |
| 91 | |
| 92 | Raises: |
| 93 | TimeoutException: If 'method' does not return a truthy value within |
| 94 | the WebDriverWait object's timeout. |
| 95 | |
| 96 | Example: |
| 97 | >>> from selenium.webdriver.common.by import By |
| 98 | >>> from selenium.webdriver.support.ui import WebDriverWait |
| 99 | >>> from selenium.webdriver.support import expected_conditions as EC |
| 100 | >>> |
| 101 | >>> # Wait until an element is visible on the page |
| 102 | >>> wait = WebDriverWait(driver, 10) |
| 103 | >>> element = wait.until(EC.visibility_of_element_located((By.ID, "exampleId"))) |
| 104 | >>> print(element.text) |
| 105 | """ |
| 106 | screen = None |
| 107 | stacktrace = None |
| 108 | |
| 109 | end_time = time.monotonic() + self._timeout |
| 110 | while True: |
| 111 | try: |
| 112 | value = method(self._driver) |
| 113 | if value: |
| 114 | return value |
| 115 | except self._ignored_exceptions as exc: |
| 116 | screen = getattr(exc, "screen", None) |
| 117 | stacktrace = getattr(exc, "stacktrace", None) |
| 118 | if time.monotonic() > end_time: |
| 119 | break |
| 120 | time.sleep(self._poll) |
| 121 | raise TimeoutException(message, screen, stacktrace) |
| 122 | |
| 123 | def until_not(self, method: Callable[[D], T], message: str = "") -> T | Literal[True]: |
| 124 | """Wait until the method returns a value that is False. |