Get Text task | Zoho QEngine Help

Get Text task

In a nutshell

The Get Text task retrieves the visible text of a web element during test execution and stores it in a variable. This is useful when the text is dynamic, such as a selected currency, live price, or status message. The stored value can then be used in later steps to verify the displayed text, compare it with another value, or determine the next action in the test.

1. Overview

The Get Text task retrieves the visible text of a web element during test execution and stores it into a variable as a string. It's used for values that may change while the test is running, such as a dropdown's selected option, a changing count, or a label that updates after an action.
The captured value can be used in a later assertion to compare it against expected data, or used to decide the next step in the test case based on what the page displays.
NotesNote: Get Text returns exactly what's rendered in the element, including any label text or whitespace bundled into the same element.

2. Syntax

<variable> = getText(<locator>);


ParameterData TypeDescription
variableSTRINGStores the text retrieved from the element.
locatorSTRINGIdentifies the element to retrieve text from.
NotesNote: 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.


Return Type

STRING

3. Examples

Example 1: Reading the currently selected currency

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-containerLocator for the currency dropdown.
selectedCurrencyVariable storing the retrieved currency text.

Example 2: Deciding the next step based on the cart confirmation message

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-cartLocator for the Add to Cart button.
10Maximum time to wait for the message to appear, in seconds.
.theme-cart-add-success-messageLocator for the cart confirmation message.
event.SHOWWaits until the message becomes visible.
cartMessageVariable storing the retrieved message text.
"Added to cart"Expected text used to decide the next step.

Example 3: Checking the tracking link after an order ships in an e-commerce application

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.
orderStatusVariable 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_ERRORStops the test if the tracking link isn't visible.

Example 4: Reading a stock status label in a Inventory Manager application

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-rowLocator for the inventory record.
ui.inventorymanager.stock-status-labelLocator for the stock status label.
stockStatusVariable storing the retrieved status text.

4. Use cases

Scenario 1: Confirming a return request's status updates after approval

Consider an ecommerce application where customers submit a return request. After the request is approved, the status displayed on the request details page should update from Pending to Approved.
A tester uses Zoho QEngine to store the request's status before and after the approval action, confirming the displayed status changes from Pending to Approved once the request is approved.


Steps

  1. Open the return request details page in the same window.
  2. Store the status label's value in a variable named statusBefore.
  3. Approve the return request.
  4. Wait for the status update to complete.
  5. Store the status label's value in a variable named statusAfter.
  6. Confirm the status changed to Approved.

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);
Scenario 2: Confirming the visible strap label matches the selected option

Shoppers select a strap material from a dropdown before adding a product to their cart, and the visible label needs to reflect the option they just picked.
A tester uses Zoho QEngine to select an option in the Strap Material dropdown, then reads the dropdown's visible label to confirm it reflects the selected option.

Steps

  1. Open the Diver Chronomat product page in the same window.
  2. Select the Leather option in the Strap Material dropdown by its position.
  3. Store the selected option's visible text in a variable.
  4. Confirm the label reads "Leather."

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);
Scenario 3: Confirming a lease's status before proceeding with renewal

Consider a Zoho Creator Lease Tracker application property managers use to manage tenant leases. Before starting the renewal process on a lease record, staff need to confirm the lease is actually active, rather than already terminated or expired.
A tester uses Zoho QEngine to confirm that the test correctly reads the lease's status, and clicks Renew Lease only when the status is Active.

Steps

  1. Open the lease record in the Lease Tracker application.
  2. Click the lease record to open it in Detail View.
  3. Store the lease status field's value in a <variable>.
  4. If the status reads Active, click Renew Lease and confirm the Lease Renewal form opens.

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
}

5. Points to note

  1. Use Get Text to retrieve an element's visible text for use in later steps, such as comparisons or conditional logic, while Assert Text validates that displayed text matches an expected value directly.
  2. Get Text retrieves exactly what is rendered within an element, including any label text or whitespace. For example, it returns an empty string ("") when the target element renders no text, such as a dropdown with no default option selected.
  3. Get Text only reads from the currently active window, tab, or iframe. Use the Switch To task first if the target element lives in a different context.
  4. Prefer a stable locator for the element being read, such as ID, name, or CSS attribute selector when using the Get Text task. Dynamic text elements, like a price or status label, change frequently, so a full XPath string is more likely to break than a locator tied to the element itself.

6. Related topics

  1. Assert Text
  2. Get Attribute
  3. Info

7. What's next

Next step
Previous step
Next step

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.

Previous step

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.