Searches for the specified element by the given selector. Raises an exception if the element is still present after the specified timeout. @Params driver - the webdriver object selector - the locator for identifying the page element (required) by - the type of selector b
(
driver,
selector,
by="css selector",
timeout=settings.LARGE_TIMEOUT,
original_selector=None,
)
| 1094 | |
| 1095 | |
| 1096 | def wait_for_element_absent( |
| 1097 | driver, |
| 1098 | selector, |
| 1099 | by="css selector", |
| 1100 | timeout=settings.LARGE_TIMEOUT, |
| 1101 | original_selector=None, |
| 1102 | ): |
| 1103 | """ |
| 1104 | Searches for the specified element by the given selector. |
| 1105 | Raises an exception if the element is still present after the |
| 1106 | specified timeout. |
| 1107 | @Params |
| 1108 | driver - the webdriver object |
| 1109 | selector - the locator for identifying the page element (required) |
| 1110 | by - the type of selector being used (Default: "css selector") |
| 1111 | timeout - the time to wait for elements in seconds |
| 1112 | original_selector - handle pre-converted ":contains(TEXT)" selector |
| 1113 | """ |
| 1114 | if __is_cdp_swap_needed(driver): |
| 1115 | if page_utils.is_valid_by(by): |
| 1116 | original_selector = selector |
| 1117 | elif page_utils.is_valid_by(selector): |
| 1118 | original_selector = by |
| 1119 | selector, by = page_utils.recalculate_selector(original_selector, by) |
| 1120 | driver.cdp.wait_for_element_absent(selector) |
| 1121 | return True |
| 1122 | _reconnect_if_disconnected(driver) |
| 1123 | start_ms = time.time() * 1000.0 |
| 1124 | stop_ms = start_ms + (timeout * 1000.0) |
| 1125 | for x in range(int(timeout * 10)): |
| 1126 | shared_utils.check_if_time_limit_exceeded() |
| 1127 | try: |
| 1128 | driver.find_element(by=by, value=selector) |
| 1129 | now_ms = time.time() * 1000.0 |
| 1130 | if now_ms >= stop_ms: |
| 1131 | break |
| 1132 | time.sleep(0.1) |
| 1133 | except Exception: |
| 1134 | return True |
| 1135 | plural = "s" |
| 1136 | if timeout == 1: |
| 1137 | plural = "" |
| 1138 | if ( |
| 1139 | original_selector |
| 1140 | and ":contains(" in original_selector |
| 1141 | and "contains(." in selector |
| 1142 | ): |
| 1143 | selector = original_selector |
| 1144 | message = "Element {%s} was still present after %s second%s!" % ( |
| 1145 | selector, |
| 1146 | timeout, |
| 1147 | plural, |
| 1148 | ) |
| 1149 | timeout_exception(Exception, message) |
| 1150 | |
| 1151 | |
| 1152 | def wait_for_element_not_visible( |
nothing calls this directly
no test coverage detected
searching dependent graphs…