Skip to content

browser.check_if#

Functions#

contains_any_text(xpath) #

Check if element contains any text.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element contains any text, False otherwise.

Example
if browser.check_if.contains_any_text("//xpath/to/button"):
    browser.click.button("//xpath/to/button")

contains_text(xpath, regex, ignore_case=True) #

Check if element contains text.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required
regex str

Regular expression or text to search for. The condition works for both ordinary text (e.g. "Submit") or regular expression (e.g. r"colou?r"). Note it's a search for text, not a strict text match.

required
ignore_case bool

Ignore case when searching for text.

True

Returns:

Type Description
bool

True if element contains text specified in the regex, False otherwise.

Example

Without regular expression:

if browser.check_if.contains_text("//xpath/to/button", "Save"):
    browser.click.button("//xpath/to/button")

With regular expression:

if browser.check_if.contains_text("//xpath/to/button", r"^Submit", ignore_case=False):
    browser.click.button("//xpath/to/button")

does_exist(xpath) #

Check if element exists.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element exists, False otherwise.

Example
if browser.check_if.does_exist("//xpath/to/button"):
    browser.click.button("//xpath/to/button")

is_clickable(xpath) #

Check if element is clickable.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is clickable, False otherwise.

Example
1
2
3
4
if browser.check_if.is_clickable("//xpath/to/button"):
    browser.click.button("//xpath/to/button")
else:
    browser.open.url("https://example.com")

is_disabled(xpath) #

Check if element is disabled.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is disabled, False otherwise.

Example
if not browser.check_if.is_disabled("//xpath/to/button"):
    browser.click.button("//xpath/to/button")

is_displayed(xpath) #

Check visibility status of an element.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is displayed, False otherwise.

Example
if browser.check_if.is_displayed("//xpath/to/button"):
    browser.click.button("//xpath/to/button")

is_enabled(xpath) #

Check if element is enabled.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is enabled, False otherwise.

Example
if browser.check_if.is_enabled("//xpath/to/button"):
    browser.click.button("//xpath/to/button")

is_image_loaded(xpath) #

Check is image is loaded and ready in the DOM.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if image is loaded, False otherwise.

Example
1
2
3
if browser.check_if.is_image_loaded("//xpath/to/img"):
    image_url = browser.get.url.from_image("//xpath/to/img")
    browser.click.download(image_url)

is_in_viewport(xpath) #

Check if an element is visible in the current viewport.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is visible in the current viewport, False otherwise.

Example
1
2
3
if not browser.check_if.is_in_viewport("//xpath/to/element"):
    browser.scroll.into_view("//xpath/to/element")
browser.screenshot.visible_portion()

is_selected(xpath) #

Check if element is selected, e.g. checkbox or radio button.

Parameters:

Name Type Description Default
xpath str

XPath of the element.

required

Returns:

Type Description
bool

True if element is selected, False otherwise.

Example
1
2
3
if not browser.check_if.is_selected("//xpath/to/input"):
    browser.input.select("//xpath/to/input")
browser.click.button_if_contains_text("//xpath/to/button", "Submit")