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

Function wait_for_element_present

seleniumbase/fixtures/page_actions.py:396–451  ·  view source on GitHub ↗

Searches for the specified element by the given selector. Returns the element object if it exists in the HTML. (The element can be invisible.) Raises NoSuchElementException if the element does not exist in the HTML within the specified timeout. @Params driver - the webdriver

(
    driver,
    selector,
    by="css selector",
    timeout=settings.LARGE_TIMEOUT,
    original_selector=None,
    ignore_test_time_limit=False,
)

Source from the content-addressed store, hash-verified

394
395
396def wait_for_element_present(
397 driver,
398 selector,
399 by="css selector",
400 timeout=settings.LARGE_TIMEOUT,
401 original_selector=None,
402 ignore_test_time_limit=False,
403):
404 """
405 Searches for the specified element by the given selector. Returns the
406 element object if it exists in the HTML. (The element can be invisible.)
407 Raises NoSuchElementException if the element does not exist in the HTML
408 within the specified timeout.
409 @Params
410 driver - the webdriver object
411 selector - the locator for identifying the page element (required)
412 by - the type of selector being used (Default: "css selector")
413 timeout - the time to wait for elements in seconds
414 original_selector - handle pre-converted ":contains(TEXT)" selector
415 ignore_test_time_limit - ignore test time limit (NOT related to timeout)
416 @Returns
417 A web element object
418 """
419 _reconnect_if_disconnected(driver)
420 element = None
421 start_ms = time.time() * 1000.0
422 stop_ms = start_ms + (timeout * 1000.0)
423 for x in range(int(timeout * 10)):
424 if not ignore_test_time_limit:
425 shared_utils.check_if_time_limit_exceeded()
426 try:
427 element = driver.find_element(by=by, value=selector)
428 return element
429 except Exception:
430 now_ms = time.time() * 1000.0
431 if now_ms >= stop_ms:
432 break
433 time.sleep(0.1)
434 plural = "s"
435 if timeout == 1:
436 plural = ""
437 if not element:
438 if (
439 original_selector
440 and ":contains(" in original_selector
441 and "contains(." in selector
442 ):
443 selector = original_selector
444 message = "Element {%s} was not present after %s second%s!" % (
445 selector,
446 timeout,
447 plural,
448 )
449 timeout_exception(NoSuchElementException, message)
450 else:
451 return element
452
453

Callers 5

js_clickFunction · 0.85
send_keysFunction · 0.85
press_keysFunction · 0.85
assert_element_presentFunction · 0.85
wait_for_selectorFunction · 0.85

Calls 4

timeout_exceptionFunction · 0.85
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…