Get Attribute
Get Attribute
Section titled “Get Attribute”Type: page-get-attribute · Package: Browser v1.0.9 · Output: string
Reads the value of an HTML attribute of an element. It’s for extracting data that isn’t visible text: a button’s download link (href), an image URL (src), a hidden identifier (data-id), or an element’s state (class, disabled).
How it works
Section titled “How it works”It locates the element by its selector, waits for it to exist on the page (it doesn’t need to be visible) and returns the value of the attribute named in attribute.
- It reads the attribute as written in the HTML: a relative
href(/invoices/12.pdf) is returned relative. Download File already knows how to complete it. - It reads the attribute, not the element’s live property: for the current value of a field use Get Value.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
selector | selector | — | The element to read the attribute from. |
attribute | string | — | Name of the HTML attribute. E.g. href, src, data-id, class. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
page | ZoanPageSession | — | The page session. Omit it inside a body; outside, pass the session variable (e.g. page = page). |
timeout | number | 30000 | Maximum time in ms to wait for the element. Empty, 0 or negative: the project settings value or, if none, 30000. |
Output
Section titled “Output”Returns a string with the attribute’s value. If the element doesn’t have that attribute, the output is empty (null); an attribute without a value, like disabled, returns "".
Example
Section titled “Example”Get the download link of a document and download it:
Page Get Attribute selector = (#enlaceFactura) attribute = "href" → output: urlPdfDownload File url = urlPdf outputPath = "C:\Invoices" → output: rutaPdfFind out whether a button is disabled:
Page Get Attribute selector = (#btnEnviar) attribute = "disabled" → output: deshabilitadoIf condition = deshabilitado != null └─ then: Log message = "Submission is not available yet"Common errors
Section titled “Common errors”| Message | Cause and fix |
|---|---|
'attribute' is required. | You didn’t set the attribute name. |
Timeout 30000ms exceeded | The element didn’t appear in time. Check the selector or wait first with Wait For. |
strict mode violation: … resolved to 2 elements | The selector matches several elements. Make it more specific or add an index. |
'page' must be a ZoanPageSession. | page is empty outside a body. |
Related activities
Section titled “Related activities”- Get Text — read the visible text instead of an attribute.
- Get Value — read the value of a form field.
- Download File — download the file behind an
href.