Searches for the specified element by the given selector. Returns the element object if the element is present and visible on the page. Raises NoSuchElementException if the element does not exist in the HTML within the specified timeout. Raises ElementNotVisibleException if the
(
driver,
selector,
by="css selector",
timeout=settings.LARGE_TIMEOUT,
original_selector=None,
ignore_test_time_limit=False,
)
| 452 | |
| 453 | |
| 454 | def wait_for_element_visible( |
| 455 | driver, |
| 456 | selector, |
| 457 | by="css selector", |
| 458 | timeout=settings.LARGE_TIMEOUT, |
| 459 | original_selector=None, |
| 460 | ignore_test_time_limit=False, |
| 461 | ): |
| 462 | """ |
| 463 | Searches for the specified element by the given selector. Returns the |
| 464 | element object if the element is present and visible on the page. |
| 465 | Raises NoSuchElementException if the element does not exist in the HTML |
| 466 | within the specified timeout. |
| 467 | Raises ElementNotVisibleException if the element exists in the HTML, |
| 468 | but is not visible (eg. opacity is "0") within the specified timeout. |
| 469 | @Params |
| 470 | driver - the webdriver object (required) |
| 471 | selector - the locator for identifying the page element (required) |
| 472 | by - the type of selector being used (Default: "css selector") |
| 473 | timeout - the time to wait for elements in seconds |
| 474 | original_selector - handle pre-converted ":contains(TEXT)" selector |
| 475 | ignore_test_time_limit - ignore test time limit (NOT related to timeout) |
| 476 | @Returns |
| 477 | A web element object |
| 478 | """ |
| 479 | _reconnect_if_disconnected(driver) |
| 480 | element = None |
| 481 | is_present = False |
| 482 | start_ms = time.time() * 1000.0 |
| 483 | stop_ms = start_ms + (timeout * 1000.0) |
| 484 | for x in range(int(timeout * 10)): |
| 485 | if not ignore_test_time_limit: |
| 486 | shared_utils.check_if_time_limit_exceeded() |
| 487 | try: |
| 488 | element = driver.find_element(by=by, value=selector) |
| 489 | is_present = True |
| 490 | if element.is_displayed(): |
| 491 | return element |
| 492 | else: |
| 493 | element = None |
| 494 | raise Exception() |
| 495 | except Exception: |
| 496 | now_ms = time.time() * 1000.0 |
| 497 | if now_ms >= stop_ms: |
| 498 | break |
| 499 | time.sleep(0.1) |
| 500 | plural = "s" |
| 501 | if timeout == 1: |
| 502 | plural = "" |
| 503 | if not element and by != "link text": |
| 504 | if ( |
| 505 | original_selector |
| 506 | and ":contains(" in original_selector |
| 507 | and "contains(." in selector |
| 508 | ): |
| 509 | selector = original_selector |
| 510 | if not is_present: |
| 511 | # The element does not exist in the HTML |
no test coverage detected
searching dependent graphs…