Skip to content

browser.wait#

Functions#

for_element(xpath, timeout=None) #

Wait until element is ready in the DOM and/or on the screen.

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

Useful for single-page app elements handled by JavaScript, but also standard HTML that doesn't load immediately. This helper function ensures that DOM elements are ready before processing. The example waits for any H1 headline to be ready:

1
2
3
4
5
from browserist import Browser

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

random_seconds(min_seconds=1, max_seconds=5) #

Sleep for a random amount of time to make actions look less like a bot. The waiting time will be somewhere between the speficied minimum and maximum seconds.

Parameters:

Name Type Description Default
min_seconds float

Minimum seconds to wait.

1
max_seconds float

Maximum seconds to wait.

5
Example

For example, wait between 3 and 20 seconds:

browser.wait.random_seconds(3, 20)

seconds(seconds) #

Sleep for a fixed amount of time.

Parameters:

Name Type Description Default
seconds float

Seconds to wait.

required
Example

For example, wait for 5 seconds:

browser.wait.seconds(5)