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='//img', timeout=None) #

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

Parameters:

Name Type Description Default
xpath str

XPath of the element. Can target one or more images. If None, all <img> image elements are targeted.

'//img'
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. By default, this method 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()

If you don't want to target all image elements, you can target, for instance, the first image element by specifying the XPath:

    browser.wait.until.images_have_loaded("//img[1]")

Or target all image elements with a specific class:

    browser.wait.until.images_have_loaded("//img[contains(@class, 'some-class')]")

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)