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

Function wait_for_text_visible

seleniumbase/fixtures/page_actions.py:536–644  ·  view source on GitHub ↗

Searches for the specified element by the given selector. Returns the element object if the text is present in the element and visible on the page. Raises NoSuchElementException if the element does not exist in the HTML within the specified timeout. Raises ElementNotVisibleE

(
    driver,
    text,
    selector,
    by="css selector",
    timeout=settings.LARGE_TIMEOUT,
)

Source from the content-addressed store, hash-verified

534
535
536def wait_for_text_visible(
537 driver,
538 text,
539 selector,
540 by="css selector",
541 timeout=settings.LARGE_TIMEOUT,
542):
543 """
544 Searches for the specified element by the given selector. Returns the
545 element object if the text is present in the element and visible
546 on the page.
547 Raises NoSuchElementException if the element does not exist in the HTML
548 within the specified timeout.
549 Raises ElementNotVisibleException if the element exists in the HTML,
550 but the text is not visible within the specified timeout.
551 @Params
552 driver - the webdriver object (required)
553 text - the text that is being searched for in the element (required)
554 selector - the locator for identifying the page element (required)
555 by - the type of selector being used (Default: "css selector")
556 timeout - the time to wait for elements in seconds
557 browser - used to handle a special edge case when using Safari
558 @Returns
559 A web element object that contains the text searched for
560 """
561 _reconnect_if_disconnected(driver)
562 element = None
563 is_present = False
564 full_text = None
565 text = str(text)
566 start_ms = time.time() * 1000.0
567 stop_ms = start_ms + (timeout * 1000.0)
568 for x in range(int(timeout * 10)):
569 shared_utils.check_if_time_limit_exceeded()
570 full_text = None
571 try:
572 element = driver.find_element(by=by, value=selector)
573 is_present = True
574 if (
575 element.tag_name.lower() in ["input", "textarea"]
576 and not shared_utils.is_safari(driver)
577 ):
578 if (
579 element.is_displayed()
580 and text in element.get_property("value")
581 ):
582 return element
583 else:
584 if element.is_displayed():
585 full_text = element.get_property("value").strip()
586 element = None
587 raise Exception()
588 elif shared_utils.is_safari(driver):
589 text_attr = "innerText"
590 if element.tag_name.lower() in ["input", "textarea"]:
591 text_attr = "value"
592 if (
593 element.is_displayed()

Callers 2

assert_textFunction · 0.85
wait_for_textFunction · 0.85

Calls 6

timeout_exceptionFunction · 0.85
get_propertyMethod · 0.80
find_elementMethod · 0.45
get_attributeMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…