In a nutshell
Note: Clear only works on input-type elements that hold a typed value, such as a text box or number field. Dropdowns and checkboxes don't hold a typed value, they hold a selection or a checked state instead. For dropdown fields, use Select or Deselect, and for checkboxes, use Check or Uncheck.clear(<locator>);
| Parameter | Data Type | Description |
| locator | STRING | Identifies the input element to clear. 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 |
Clears the search box on the ZWatch Commerce site so a fresh search term can be entered without appending to what was searched before.
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Clear the search box using the Clear task
clear(ui.zwatch.search-box);where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| ui.zwatch.search-box | Stored locator for the search box. |
Clears a pre-filled email field on the login page, then confirms an error message appears when the form is submitted without it.
// Open the login page on the ZWatch Commerce website using the Open URL task
openURL("https://zwatch.zohocommerce.com/login", "same window");
// Clear the email field using the Clear task
clear(ui.zwatch.email-field);
// Attempt to submit the form using the Click task
click(ui.zwatch.login-submit-button);
// Confirm the required-field error message appears using the Assert Visible task
assertVisible(ui.zwatch.email-required-error, errorhandling.STOP_ON_ERROR);where:
| "https://zwatch.zohocommerce.com/login" | Login page URL. |
| "same window" | Opens the page in the window already running the test. |
| ui.zwatch.email-field | Stored locator for the email field. |
| ui.zwatch.login-submit-button | Stored locator for the login submit button. |
| ui.zwatch.email-required-error | Stored locator for the required-field error message. |
| errorhandling.STOP_ON_ERROR | Stops the test if the error message doesn't appear. |
Clears the search box, then uses the <Send Keys> task to type a new query character by character. Because the site's live suggestions respond only to keyboard input.
// Open the watch listing page on the ZWatch Commerce website using the Open URL task
openURL("https://zwatch.zohocommerce.com/collections/watches", "same window");
// Clear the search box using the Clear task
clear(ui.zwatch.search-box);
// Type a new query using the Send Keys task so the live suggestion dropdown responds
sendKeys(ui.zwatch.search-box, "Chrono");where:
| "https://zwatch.zohocommerce.com/collections/watches" | Watch listing page URL. |
| "same window" | Opens the page in the window already running the test. |
| ui.zwatch.search-box | Stored locator for the search box. |
| "Chrono" | Query typed character by character to trigger the live suggestion dropdown. |
Clears a default amount field on an expense entry form, built on Zoho Creator, before entering the actual expense amount.
// Open the expense entry form in the Expense Tracker application using the Open URL task
openURL("https://creatorapp.zoho.com/zylker/expense-tracker#Form:Expense_Entry", "same window");
// Clear the amount field using the Clear task
clear(ui.expensetracker.amount-field);
// Enter the actual expense amount using the Set Value task
setValue(ui.expensetracker.amount-field, "245.50");where:
| "https://creatorapp.zoho.com/zylker/expense-tracker#Form:Expense_Entry" | Expense entry form URL. |
| "same window" | Opens the form in the window already running the test. |
| ui.expensetracker.amount-field | Stored locator for the amount field. |
| "245.50" | The actual expense amount to enter after clearing the default. |
Signup forms typically pre-populate certain fields with remembered values, but required-field validation should still prevent submission when those values are cleared.
Zoho QEngine automates a check of this validation path. It clears the shipping address field, attempts to submit the form, and confirms the form blocks submission with a visible error. If the validation passes with an empty field, incomplete orders could reach fulfillment with no shipping address at all.
Steps
Implementation
// Step 1: Open the checkout page on the ZWatch Commerce website in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/checkout", "same window");
// Step 2: Clear the shipping address field using the Clear task
clear(ui.zwatch.shipping-address-field);
// Step 3: Attempt to complete the order using the Click task
click(ui.zwatch.place-order-button);
// Step 4: Confirm the required-field error message appears using the Assert Visible task
assertVisible(ui.zwatch.shipping-address-required-error, errorhandling.STOP_ON_ERROR);Shoppers often run more than one search in the same visit, refining or completely changing what they're looking for. If the search box doesn't fully clear between searches, a new query could get appended to the old one and return incorrect or no results.
Zoho QEngine automates a check of this reset behavior. It runs an initial search, clears the search box, enters a different search term, and confirms the results reflect only the new query. If the field failed to clear, the second search could fail with no results or return a mix of unrelated results.
Steps
Implementation
// Step 1: Open the watch listing page on the ZWatch Commerce website in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/collections/watches", "same window");
// Step 2: Enter an initial search term using the Set Value task
setValue(ui.zwatch.search-box, "Daytona");
// Step 3: Clear the search box using the Clear task
clear(ui.zwatch.search-box);
// Step 4: Enter a different search term using the Set Value task
setValue(ui.zwatch.search-box, "Chronomat");
// Step 5: Confirm the results reflect only the new search term using the Assert Text task
assertText(ui.zwatch.search-results-heading, "Results for Chronomat", errorhandling.STOP_ON_ERROR);Scenario 3: Clearing a search field between consecutive lookups on an expense dashboard
Consider a finance organization that uses a Zoho Creator Expense Tracker application. The application's Expense Dashboard page includes a search field that lets staff quickly locate expense records by employee name, expense ID, or category. Staff often perform multiple searches in succession while reviewing expenses. Before entering a new search term, they clear the existing value to ensure the next search is performed independently and returns the correct results.
A tester uses Zoho QEngine to verify that clearing the search field removes the previous search term completely, allowing the next search to execute using only the newly entered value.
Steps
Implementation
// Step 1: Open the Expense Dashboard page in the Expense Tracker application using the Open URL task
openURL("https://creatorapp.zoho.com/zylker/expense-tracker#Page:Expense_Dashboard", "same window");
// Step 2: Search for an initial expense record using the Set Value task
setValue(ui.expensetracker.search-field, "Taxi - March");
// Step 3: Clear the search field using the Clear task
clear(ui.expensetracker.search-field);
// Step 4: Enter a different search term using the Set Value task
setValue(ui.expensetracker.search-field, "Hotel - April");
// Step 5: Confirm the page displays results only for the new search term using the Assert Text task
assertText(ui.expensetracker.record-count, "1 record found", errorhandling.STOP_ON_ERROR);