Clear task | Zoho QEngine Help

Clear task

In a nutshell

The Clear task empties the current value of an input field on a webpage. This lets your test start with an empty field before entering a new value or validating a workflow that requires no input.

1. Overview

The Clear task removes the current value from an input-type element, such as a text box, number field, or date field, returning it to an empty state.

It is commonly used before entering new data, validating how a form behaves when a required field is left empty, or resetting a value that was entered incorrectly. By automating these interactions, testers can confirm that the application correctly handles empty input and processes whatever is entered afterward as expected.

For example, a quantity field on a product page starts at "1" by default. That value needs to be cleared before a new number can be entered.
NotesNote: 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.

2. Syntax

clear(<locator>);


ParameterData TypeDescription
locatorSTRINGIdentifies the input element to clear.
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

3. Examples

Example 1: Clearing a search box before entering a new query

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-boxStored locator for the search box.

Example 2: Testing empty-field validation on a login form

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-fieldStored locator for the email field.
ui.zwatch.login-submit-buttonStored locator for the login submit button.
ui.zwatch.email-required-errorStored locator for the required-field error message.
errorhandling.STOP_ON_ERRORStops 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-boxStored locator for the search box.
"Chrono"Query typed character by character to trigger the live suggestion dropdown.

Example 4: Correcting a pre-filled amount field on an expense entry form

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-fieldStored locator for the amount field.
"245.50"The actual expense amount to enter after clearing the default.

4. Use cases

Scenario 1: Verifying a required field blocks submission when left empty

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

  1. Open the checkout page in the same window.
  2. Clear the shipping address field.
  3. Attempt to complete the order.
  4. Confirm the required-field error message appears.

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);

Scenario 2: Starting a fresh product search after a previous query

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

  1. Open the watch listing page in the same window.
  2. Enter "Daytona" in the search box.
  3. Clear the search box.
  4. Enter "Chronomat" in the search box.
  5. Confirm the results show only Chronomat products.

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

  1. Open the Expense Dashboard page in the Expense Tracker application.
  2. Search for an initial expense record.
  3. Clear the search field.
  4. Enter a different search term.
  5. Confirm that the page displays results only for the new search term.

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);

5. Points to note

  1. Use Clear only to empty an existing value, it doesn't type new data into the field. Follow it with a Set Value or Send Keys task to enter fresh input.
  2. Use Deselect or Uncheck for dropdowns and checkboxes, Clear applies to input-type elements such as text fields and text areas.
  3. Prefer logical locators, such as field labels or names, over raw full XPath strings when locating the input element.
  1. Set Value
  2. Send Keys
  3. Deselect
  4. Uncheck
  5. Upload

7. What's next

Next step
Previous step
Next step
Now that you've used the Clear task to empty an input field, learn how to upload a file to a webpage using the Upload task.
Previous step
Before using the Clear task, learn how the other form tasks, such as Select, Deselect, Check, and Uncheck, work.