In a nutshell
Note: Get Text returns exactly what's rendered in the element, including any label text or whitespace bundled into the same element.<variable> = getText(<locator>);
| Parameter | Data Type | Description |
| variable | STRING | Stores the text retrieved from the element. |
| locator | STRING | Identifies the element to retrieve text from. 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. |
Check the currently selected currency in the dropdown and log its value.
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Read the currency dropdown's rendered text using the Get Text task
selectedCurrency = getText(".theme-currency-option-container");
// output: "Currency :\n\n INR"
// Log the retrieved value using the Info task
info(selectedCurrency);where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| .theme-currency-option-container | Locator for the currency dropdown. |
| selectedCurrency | Variable storing the retrieved currency text. |
Retrieve the cart confirmation message after adding an item to the cart. Use its value to decide the next step in the test case.
// 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");
// Add the product to the cart using the Click task
click(".theme-product-qty-and-add-cart");
// Wait until the cart confirmation message becomes visible
wait(10, ".theme-cart-add-success-message", event.SHOW);
// Read the cart confirmation message using the Get Text task
cartMessage = getText(".theme-cart-add-success-message");
// output: "Added to cart"
// Decide the next step based on the retrieved message using a conditional logic task
if (cartMessage == "Added to cart")
{
info("Item added successfully; proceeding with checkout.");
}
else
{
throwError("Cart confirmation message did not match the expected text.");
}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. |
| .theme-product-qty-and-add-cart | Locator for the Add to Cart button. |
| 10 | Maximum time to wait for the message to appear, in seconds. |
| .theme-cart-add-success-message | Locator for the cart confirmation message. |
| event.SHOW | Waits until the message becomes visible. |
| cartMessage | Variable storing the retrieved message text. |
| "Added to cart" | Expected text used to decide the next step. |
On the order page of an e-commerce application, the status label shows where the order stands. Check the label’s value to confirm the tracking link is visible once the order has shipped.
// Open the order page using the Open URL task
openURL("https://www.<website_name>.com/<order_page>", "same window");
// Read the order status label using the Get Text task
orderStatus = getText(ui.<order_page>.<status_label>);
// output: "Shipped"
// Confirm the tracking link is visible if the order has shipped using a conditional logic task
if (orderStatus == "Shipped")
{
assertVisible(ui.<order_page>.<tracking_link>, errorhandling.STOP_ON_ERROR); //Learn more about Assert Visible task
}where:
| "https://www.<website_name>.com/<order_page>" | Order page URL. |
| "same window" | Opens the page in the window already running the test. |
| ui.<order_page>.<status_label> | Locator for the order status label. |
| orderStatus | Variable storing the retrieved status text. |
| "Shipped" | Expected status value that triggers the tracking link check. |
| ui.<order_page>.<tracking_link> | Locator for the tracking link, checked once the order has shipped. |
| errorhandling.STOP_ON_ERROR | Stops the test if the tracking link isn't visible. |
Check the stock status label on an inventory record in a Zoho Creator Inventory Manager application and log its value.
// Open the Inventory report in the Inventory Manager application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/inventory-manager#Report:Inventory", "same window");
// Click the inventory record to open it using the Click task
click(ui.inventorymanager.inventory-record-row);
// Read the stock status label using the Get Text task
stockStatus = getText(ui.inventorymanager.stock-status-label);
// Log the retrieved value using the Info task
info(stockStatus);where:
| "https://creatorapp.zoho.com/<orgname>/inventory-manager#Report:Inventory" | Inventory report URL. |
| "same window" | Opens the report in the window already running the test. |
| ui.inventorymanager.inventory-record-row | Locator for the inventory record. |
| ui.inventorymanager.stock-status-label | Locator for the stock status label. |
| stockStatus | Variable storing the retrieved status text. |
Steps
Implementation
// Step 1: Open the return request details page using the Open URL task
openURL("<webpage_url>/returns/<request_id>", "same window");
// Step 2: Store the status label's value in a variable named statusBefore using the Get Text task
statusBefore = getText(ui.<returns_page>.<status_label>);
// Step 3: Approve the return request using the Click task
click(ui.<returns_page>.<approve_button>);
// Step 4: Wait for the status update to complete
wait(5);
// Step 5: Store the status label's value in a variable named statusAfter using the Get Text task
statusAfter = getText(ui.<returns_page>.<status_label>);
// Step 6: Confirm the status changed to Approved using the Assert Text task
assertText(ui.<returns_page>.<status_label>, "Approved", errorhandling.STOP_ON_ERROR);Steps
Implementation
// Step 1: Open the Diver Chronomat product page on the ZWatch Commerce website in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722", "same window");
// Step 2: Select the Leather option in the Strap Material dropdown using the Select task
select("select[data-zs-attribute-name='Strap Material']", "1", select.INDEX);
// Step 3: Store the selected option's visible text in a variable using the Get Text task
selectedLabel = getText("select[data-zs-attribute-name='Strap Material'] option:checked");
// Step 4: Confirm the label reads Leather using the Assert Text task
assertText("select[data-zs-attribute-name='Strap Material'] option:checked", "Leather", errorhandling.STOP_ON_ERROR);Steps
Implementation
// Step 1: Open the Leases report in the Lease Tracker application using the Open URL task
openURL("https://creatorapp.zoho.com/orgname/lease-tracker#Report:Leases", "same window");
// Step 2: Click the tenant's lease record to open it in Detail View using the Click task
click(ui.leasetracker.lease-record-row);
// Step 3: Store the lease status field's value in a variable using the Get Text task
leaseStatus = getText(ui.leasetracker.lease-status-field);
// Step 4: Click Renew Lease and confirm the form opens if the status reads Active using conditional logic task
if (leaseStatus == "Active")
{
click(ui.leasetracker.renew-lease-button);
assertVisible(ui.leasetracker.lease-renewal-form, errorhandling.STOP_ON_ERROR); //Learn more about Assert Visible
}
// Step 5: Otherwise, log that the lease isn't active
else
{
info("Lease is not active; skipping renewal check."); //Learn more about Info task
}Now that you've learned how to retrieve an element's text using the Get Text task, learn how to retrieve an element's attribute value using the Get Attribute task.
Before learning about the Get Text task, you may want to learn about the Miscellaneous group or explore the full set of tasks in the group.