Skip to content

browser.get#

Functions#

dimensions(xpath, timeout=None) #

Get width and height of element on the current page 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 on the current page 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
1
2
element = browser.get.element("//xpath/to/element")
print(element.text)

elements(xpath, timeout=None) #

Get multiple WebElements on the current page 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 on the current page 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)

meta_description() #

Get meta description of the current page.

Returns:

Type Description
str

The meta description content of the current page. If no meta description is found, an empty string is returned.

Example
1
2
meta_description = browser.get.meta_description()
print(meta_description)

meta_robots() #

Get meta robots configuration of the current page.

Returns:

Type Description
str

The content of meta robots of the current page. For example, if a page has <meta name="robots" content="nofollow, noindex"> in the header, this will return the nofollow, noindex part. If no meta robots definition is found, an empty string is returned.

Example
1
2
meta_robots = browser.get.meta_robots()
print(meta_robots)

page_title() #

Get page title of the current page.

Returns:

Type Description
str

Page title of the current page.

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

text(xpath, timeout=None) #

Get text from element on the current page.

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
1
2
element_text = browser.get.text("//xpath/to/element")
print(element_text)

texts(xpath, timeout=None) #

Get array of texts from elements on the current page. 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)