Appearance
UI.getAttributes()
Gets all HTML attributes from an element and returns them as a key–value map.
Usage
js
var attr = UI.getAttributes(element: string)Parameters
| Parameter | Type | Description |
|---|---|---|
element | string | Target element — by CSS or XPath selector |
Returns
A map where:
- each
keyis the attribute name - each
valueis the attribute value as a string
Example
Take the following checkbox as an example:
Demo
UI
HTML
<!--[--><label>
<input id="notify-stock-checkbox" type="checkbox" class="pretty-checkbox" data-product-id="PRD_3820" checked=""> Notify me when it is in stock
</label>
<!--]-->We can retrieve all attributes of the checkbox using:
js
var attr = UI.getAttributes("#notify-stock-checkbox")This returns a map with the following contents:
javascript
{
"id": "notify-stock-checkbox",
"type": "checkbox",
"class": "pretty-checkbox",
"data-product-id": "PRD_3820",
"checked": ""
}We can then read individual attribute values from the map and perform custom logging or assertions. Here is a complete example:
javascript
var attr = UI.getAttributes("#notify-stock-checkbox")
var productID = attr["data-product-id"]
if (!productID) {
TEST.log.fail("Missing 'data-product-id' attribute")
} else {
TEST.log.info("Product ID: ", productID)
}