browser.get.attribute#
Functions#
value(xpath, attribute, timeout=None)
#
Get value from an attribute of an element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the element. | required |
attribute | str | Attribute name. | required |
timeout | float | None | In seconds. Timeout to wait for element. If | None |
Returns:
Type | Description |
---|---|
str | None | Value of the attribute. If the attribute does not exist, |
Example
Use src
as attribute to get the source URL from an <img>
image element.
image_url = browser.get.attribute.value("//xpath/to/img", "src")
Use href
as attribute to get the URL from an <a>
link element.
link_url = browser.get.attribute.value("//xpath/to/a", "href")
Or use other attributes to get the value from a <meta>
element in the <head>
section.
meta_content = browser.get.attribute.value("/html/head/meta[1]", "content")
values(xpath, attribute, timeout=None)
#
Get values from an attribute of multiple elements. Assumes that the XPath targets multiple links.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xpath | str | XPath of the elements. | required |
attribute | str | Attribute name. | required |
timeout | float | None | In seconds. Timeout to wait for element. If | None |
Returns:
Type | Description |
---|---|
list[str | None] | Values of the attribute. If an attribute does not exist, |
Example
Use src
as attribute to get the source URL from <img>
image elements.
image_urls = browser.get.attribute.values("//img", "src")
Use href
as attribute to get the URL from <a>
link elements.
link_urls = browser.get.attribute.values("//a", "href")
Or use other attributes to get values from <meta>
elements in the <head>
section.
meta_contents = browser.get.attribute.values("/html/head/meta", "content")