Skip to content

browser.wait.until#

Functions#

contains_any_text(xpath, timeout=None) #

Wait until element contains any text, e.g. an element in a single-page application that loads later than first page paint.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None
Example
1
2
3
4
5
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.wait.until.contains_any_text("//h1")

element_disappears(xpath, timeout=None) #

Wait until element doesn't exist.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required
timeout float | None

In seconds. Timeout to wait for element to disappear. If None, the global timeout setting is used (default 5 seconds).

None
Example
1
2
3
4
5
6
7
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.input.value("//xpath/to/input", "test")
    browser.click.button("//xpath/to/button")
    browser.wait.until.element_disappears("//xpath/to/input")

images_have_loaded(xpath, timeout=None) #

Wait until image(s) have loaded on the page.

Parameters:

Name Type Description Default
xpath str

XPath of the element. Can target one or more images.

required
timeout float | None

In seconds. Timeout to wait for element(s) to be loaded. If None, the global timeout setting is used (default 5 seconds).

None
Example

As images often load after first page paint and sometimes require extra time to download, it's useful know when a specific image or all images have loaded. The example targets all image elements on a page:

1
2
3
4
5
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.wait.until.images_have_loaded("//img")

is_clickable(xpath, timeout=None) #

Wait until element is clickable.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required
timeout float | None

In seconds. Timeout to wait for element. If None, the global timeout setting is used (default 5 seconds).

None
Example
1
2
3
4
5
6
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.wait.until.is_clickable("//xpath/to/button")
    browser.click.button("//xpath/to/button")

number_of_window_handles_is(expected_handles, timeout=None) #

Wait until number of window handles is.

Note

Useful when working with multiple tabs or browser windows as they sometimes take time to load.

Parameters:

Name Type Description Default
expected_handles int

Expected number of window handles.

required
timeout float | None

In seconds. Timeout to wait for operation. If None, the global timeout setting is used (default 5 seconds).

None
Example
1
2
3
4
5
6
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.window.open.new_tab("https://google.com")
    browser.wait.until.number_of_window_handles_is(2)