MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / wait_for_element_absent

Function wait_for_element_absent

seleniumbase/fixtures/page_actions.py:1096–1149  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1094
1095
1096def 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
1152def wait_for_element_not_visible(

Callers

nothing calls this directly

Calls 6

timeout_exceptionFunction · 0.85
__is_cdp_swap_neededFunction · 0.70
find_elementMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…