In a nutshell
<variable> = getAttribute(<locator>, <attribute>);
| Parameter | Data Type | Description |
| variable | STRING | Stores the attribute value retrieved from the element. |
| locator | STRING | Identifies the element whose attribute value should be retrieved. Note: Locators can be fetched in one of two ways, either by manually inspecting the webpage to identify the element, or by using a recorded element saved during a recording session. Learn more about Elements. |
| attribute | STRING | Name of the attribute to retrieve, such as alt, href, or a custom data attribute. |
// Open the Blue Bay GMT product page on the ZWatch Commerce website using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/blue-bay-gmt/3531661000000075668", "same window");
// Read the product image's alt attribute using the Get Attribute task
altText = getAttribute(ui.zwatch.blue-bay-gmt-image, "alt");
// Confirm the alt text contains the product name using the conditional logic task
if (!altText.containsIgnoreCase("Blue Bay GMT"))
{
throwError("Product image alt text does not contain the expected product name"); //Learn more about Throw Error task
}
where:
| "https://zwatch.zohocommerce.com/products/blue-bay-gmt/3531661000000075668" | Blue Bay GMT product page URL. |
| "same window" | Opens the page in the window already running the test. |
| ui.zwatch.blue-bay-gmt-image | Stored locator for the product image. |
| "alt" | Name of the attribute to retrieve. |
| altText | Variable storing the retrieved alt text. |
| "Blue Bay GMT" | Expected product name the alt text must contain. |
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Read the Contact link's href attribute using the Get Attribute task
contactHref = getAttribute("a[href='/contact']", "href");
// Confirm the href resolves to the correct destination using conditional logic tasks
if (contactHref != "https://zwatch.zohocommerce.com/contact")
{
throwError("Contact link href does not resolve to the expected page"); //Learn more about Throw Error task
}
where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| a[href='/contact'] | Locator for the Contact link. |
| "href" | Name of the attribute to retrieve. |
| contactHref | Variable storing the retrieved href value. |
| "https://zwatch.zohocommerce.com/contact" | Expected resolved href value for the Contact link. |
// Open the Diver Chronomat product page on the ZWatch Commerce website using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722", "same window");
// Read the underlying price attribute before switching currency using the Get Attribute task
priceBefore = getAttribute("[data-zs-selling-price]", "data-zs-selling-price");
// Click the currency dropdown using the Click task
click(".theme-currency-option-container");
// Select USD from the currency dropdown using the Click task
click(ui.zwatch.currency-usd-option);
// Read the underlying price attribute again using the Get Attribute task
priceAfter = getAttribute("[data-zs-selling-price]", "data-zs-selling-price");
// Confirm both readings match using the conditional logic task
if (priceAfter != priceBefore)
{
throwError("Underlying price attribute changed unexpectedly after switching currency"); //Learn more about Throw Error task
}where:
| "https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722" | Diver Chronomat product page URL. |
| "same window" | Opens the page in the window already running the test. |
| [data-zs-selling-price] | Locator for the displayed price. |
| "data-zs-selling-price" | Name of the attribute to retrieve. |
| priceBefore | Variable storing the price attribute read before switching currency. |
| .theme-currency-option-container | Locator for the currency selector. |
| ui.zwatch.currency-usd-option | Stored locator for the USD option in the currency selector. |
| priceAfter | Variable storing the price attribute read after switching currency. |
// Open the Leases report in a Zoho Creator Lease Tracker application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/lease-tracker#Report:Leases", "same window");
// Read the lease record's ID attribute using the Get Attribute task
recordId = getAttribute(ui.leasetracker.lease-record-row, "data-record-id");
// Confirm the record ID matches the expected value using conditional logic tasks
if (recordId != "4771000000123456")
{
throwError("Lease record ID does not match the expected value"); //Learn more about Throw Error task
}where:
| "https://creatorapp.zoho.com/<orgname>/lease-tracker#Report:Leases" | URL of the Leases report in a Zoho Creator Lease Tracker application. |
| "same window" | Opens the report in the window already running the test. |
| ui.leasetracker.lease-record-row | Locator for the lease record row. |
| "data-record-id" | Name of the attribute to retrieve. |
| recordId | Variable storing the retrieved record ID. |
| "4771000000123456" | Expected record ID for the lease record. |
Implementation
// Step 1: Open the Blue Bay GMT product page on the ZWatch Commerce website in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/blue-bay-gmt/3531661000000075668", "same window");
// Step 2: Read the product image's alt attribute and store the value in a variable using the Get Attribute task
altText = getAttribute(ui.zwatch.blue-bay-gmt-image, "alt");
// Step 3: Confirm the alt text contains the product name using the conditional logic task
if (!altText.containsIgnoreCase("Blue Bay GMT"))
{
throwError("Product image alt text does not contain the expected product name"); //Learn more about Throw Error task
}Implementation
// Step 1: Open the ZWatch Commerce home page in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the currency selector to reveal the currency options using the Click task
click(".theme-currency-option-container");
// Step 3: Select USD from the currency selector using the Click task
click(ui.zwatch.currency-usd-option);
// Step 4: Read the currency selector's underlying attribute and store the value in a variable using the Get Attribute task
selectedCurrency = getAttribute(".theme-currency-option-container", "data-currency-code");
// Step 5: Confirm the attribute reflects the USD selection using the conditional logic task
if (selectedCurrency != "USD")
{
throwError("Currency selector attribute does not reflect the USD selection"); //Learn more about Throw Error task
}Implementation
// Step 1: Open the Candidates report in a Zoho Creator Recruitment Portal application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/recruitment-portal#Report:Candidates", "same window");
// Step 2: Click the candidate's record to open it using the Click task
click(ui.recruitmentportal.candidate-row);
// Step 3: Read the candidate's photo alt attribute and store the value in a variable using the Get Attribute task
candidatePhotoAlt = getAttribute(ui.recruitmentportal.candidate-photo, "alt");
// Step 4: Confirm the alt text contains the candidate's name using the conditional logic task
if (!candidatePhotoAlt.containsIgnoreCase("Jordan Cole"))
{
throwError("Candidate photo alt text does not contain the expected candidate name"); //Learn more about Throw Error task
}Now that you've learned how to retrieve an element's attribute value using the Get Attribute task, learn how to count the occurrences of an element using the Get Count task.
Before using the Get Attribute task, ensure that you've learned how to retrieve an element's visible text using the Get Text task.