Skip to content

browser.get#

Functions#

dimensions(xpath, timeout=None) #

Get width and height of element in pixels.

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

Returns:

Type Description
tuple[int, int]

Width and height in pixels.

Example
width, height = browser.get.dimensions("//xpath/to/element")

element(xpath, timeout=None) #

Get single WebElement by XPath.

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

Returns:

Type Description
WebElement

Web element.

Example
element = browser.get.element("//xpath/to/element")
print(element.text)

elements(xpath, timeout=None) #

Get multiple WebElements by XPath. Assumes that the XPath targets multiple elements.

Parameters:

Name Type Description Default
xpath str

XPath of the elements.

required
timeout float | None

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

None

Returns:

Type Description
list[WebElement]

List of web elements of type WebElement.

Example
1
2
3
elements = browser.get.elements("//xpath/to/elements")
for element in elements:
    print(element.text)

elements_by_tag(tag, timeout=None) #

"Get multiple WebElements by HTML tag. Assumes that the XPath targets multiple elements.

Parameters:

Name Type Description Default
tag str

HTML tag of the elements. For example, "img" as tag for all <img> images, "a" for all <a> links, etc.

required
timeout float | None

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

None

Returns:

Type Description
list[WebElement]

List of web elements of type WebElement.

Example

Get and print all paragraphs of a web page:

1
2
3
elements = browser.get.elements_by_tag("p")
for element in elements:
    print(element.text)

page_title() #

Get page title of the current page.

Returns:

Type Description
str

Page title.

Example
page_title = browser.get.page_title()
print(page_title)

text(xpath, timeout=None) #

Get text from element.

Note

This method assumes that the text field shouldn't be empty and therefore will retry to get the text (for better support of single-page apps with extended loading time).

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

Returns:

Type Description
str

Text from element.

Example
element_text = browser.get.text("//xpath/to/element")
print(element_text)

texts(xpath, timeout=None) #

Get array of texts from elements. Assumes that the XPath targets multiple elements.

Parameters:

Name Type Description Default
xpath str

XPath of the elements.

required
timeout float | None

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

None

Returns:

Type Description
list[str]

List of texts from elements.

Example
1
2
3
element_texts = browser.get.texts("//xpath/to/elements")
for element_text in element_texts:
    print(element_text)