Skip to content

browser.combo#

Functions#

cookie_banner(settings, timeout=None) #

Standardised combination of methods to accept or decline cookies.

Parameters:

Name Type Description Default
settings CookieBannerSettings

Add settings class.

required
timeout float | None

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

None

Returns:

Type Description
bool | None

If return_bool is True in the settings class, this method returns True if the cookie banner is handled succesfully. False or None otherwise.

Example
from browserist import Browser, CookieBannerSettings

accept_cookies = CookieBannerSettings(
    url="https://example.com",
    has_loaded_xpath="//xpath/to/cookie_banner",
    button_xpath="//xpath/to/accept_button")

with Browser() as browser:
    browser.combo.cookie_banner(accept_cookies)
    browser.open.url("https://example.com/some_page")
    browser.click.button("//xpath/to/button")

Or use succesfull handling of the cookie banner with a conditional if statement by setting return_bool to True as parameter in the settings class:

from browserist import Browser, CookieBannerSettings

accept_cookies = CookieBannerSettings(
    url="https://example.com",
    has_loaded_xpath="//xpath/to/cookie_banner",
    button_xpath="//xpath/to/accept_button",
    return_bool=True)

with Browser() as browser:
    if browser.combo.cookie_banner(accept_cookies):
        browser.open.url("https://example.com/some_page")
        browser.click.button("//xpath/to/button")

Configuration Classes#

CookieBannerSettings#

Settings class for the cookie banner combo.

Parameters:

Name Type Description Default
url str | None

URL from where to handle the cookie banner.

None
iframe_xpath str | None

Use if the cookie banner is inside an iframe. If used, all other XPath elements are relative to this iframe.

None
has_loaded_wait_seconds float | None

Minor grace time to ensure the cookie banner has loaded. Often due an fade-in animation or similar transition.

None
has_loaded_xpath str | None

Check if cookie banner has loaded so it's ready for interaction.

None
button_xpath str

Can be for either accept or decline cookies.

required
has_disappeared_wait_seconds float | None

Minor grace time to ensure the cookie banner has disappeared – often due an animation – and that the cookie information has been saved before proceeding.

None
return_bool bool

If set to True, the cookie banner combo can be used with a conditional if statement and return boolean True or False depending on whether the cookie banner was handled succesfully without errors or not. This will also suppresses exceptions. With default False, the cookie banner combo will not return any value.

False