Select task | Zoho QEngine Help

Select task

In a nutshell

The Select task automates choosing an option from a dropdown field on a webpage. It works the way you would click the dropdown open and pick a value during a test. It matches the option in one of three ways: by its position in the list, by the visible text, or by the underlying value the page submits.

1. Overview

The Select task sets a dropdown field on a web page to one of its available options. It fits any form field that limits input to a fixed list of choices. Each dropdown holds its own set of values behind the options shown to the user. Common examples include a payment method during checkout, a product variant on a shopping site, or a language selector on a multilingual page.

The Select task supports three types that identify which option to pick inside the dropdown:

  1. INDEX - Targets the option by its position in the dropdown. Suited to cases where you already know the option's position in the list, counting from 0 for the first option.
  2. TEXT - Matches the option by the text displayed on screen. Use this when the option's visible text is exactly what's displayed to the user.
  3. VALUE - Identifies the option by the value stored in its underlying value attribute, which the page submits even though it isn't shown on screen. Necessary when the visible text alone won't reliably identify the option, such as when the value submitted to the page differs from what's shown, for example a shipping country displayed as "India" with a value attribute of "IN".
NotesNote: Select is scoped specifically to dropdowns. For checkboxes, use the Check or Uncheck task instead.

2. Syntax

select(<locator>, <text>, <select_type>);

ParameterData TypeDescription
locatorSTRINGAddress to locate the dropdown containing the options to choose from.

Note: You can inspect from the webpage to find the locators of the elements or <record> and store the elements. Learn more about <Elements>
textSTRINGThe text or attribute value to match, according to the select type used.
select_typeSTRING

The method used to match the option inside the dropdown:

  1. select.INDEX - This indicates the specific index of an option within the dropdown. In a language selector list ordered alphabetically, index 0 selects the first entry regardless of what it displays.
  2. select.TEXT - This selects an option from a dropdown based on its visible text content. Selecting "Credit Card" from a payment method dropdown matches directly on that visible label.
  3. select.VALUE - This selects an option within the dropdown based on its underlying value attribute. A product variant might display "Medium" while the value actually submitted underneath is "M".

3. Examples

Example 1: Selecting a strap material option by position
A customer browsing the Diver Chronomat product page on the ZWatch Commerce store wants the Leather strap variant, selected from the Strap Material dropdown by its position in the list.

// Step 1: 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");
// Step 2: Select the second option in the dropdown, using index 1 since QEngine counts positions starting from 0
select("select[data-zs-attribute-name='Strap Material']", "1", select.INDEX);

where:

"https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722"URL of the Diver Chronomat product page.
"same window"Opens the product page in the window already running the test.
select[data-zs-attribute-name='Strap Material']Locator for the Strap Material dropdown on the Diver Chronomat page.
"1"Index of the Leather option in the dropdown, starting from 0.
select.INDEXSelects the option by its position rather than its text or value.

Example 2: Selecting and verifying a shipping country option

During checkout, a customer selects United States as their shipping country, and the store needs to confirm that selection actually registered before the order proceeds.

// Step 1: Open the checkout page on the ZWatch Commerce store using the Open URL task
openURL("https://zwatch.zohocommerce.com/checkout", "same window");
// Step 2: shippingCountry holds the visible text of the country to select from the dropdown
shippingCountry = "United States";
// Step 3: Select the country from the shipping country dropdown using its visible text
select(ui.zwatch.checkout-dropdown, shippingCountry, select.TEXT);
// Step 4: Confirm the United States option is now selected, stopping the test if it isn't
assertSelected(ui.zwatch.checkout-dropdown.unitedStates, errorhandling.STOP_ON_ERROR);

where:

"https://zwatch.zohocommerce.com/checkout"URL of the checkout page on the ZWatch Commerce website.
"same window"Opens the checkout page in the window already running the test.
shippingCountryVariable storing the visible text of the country to select.
ui.zwatch.checkout-dropdownStored locator for the shipping country dropdown.
select.TEXTSelects the option by matching its visible text.
ui.zwatch.checkout-dropdown.unitedStatesStored locator for the United States option within the dropdown.
errorhandling.STOP_ON_ERRORStops the test case if the United States option isn't selected.

Example 3: Selecting a strap material option by value

A different customer wants the Chain strap variant, but the dropdown submits a numeric variant ID rather than the word "Chain," so the test needs to select by that underlying value instead of the label.

// Step 1: Open the Diver Chronomat product page on the ZWatch Commerce store using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722", "same window");
// Step 2: chainValue holds the Chain option's underlying value attribute, a numeric variant ID rather than the visible "Chain" text
chainValue = "3531661000000075708";
// Step 3: Select the Chain strap option from the dropdown by its underlying value attribute
select("select[data-zs-attribute-name='Strap Material']", chainValue, select.VALUE);

where:

"https://zwatch.zohocommerce.com/products/diver-chronomat/3531661000000075722"URL of the Diver Chronomat product page.
"same window"Opens the product page in the window already running the test.
chainValueVariable storing the Chain option's underlying value attribute.
select[data-zs-attribute-name='Strap Material']Locator for the Strap Material dropdown on the Diver Chronomat page.
select.VALUESelects the option by its underlying value attribute instead of its visible text.

Example 4: Selecting an appointment type in a Zoho Creator application

This script selects the Follow-up option in the Appointment Type dropdown on a patient intake form, built on Zoho Creator, using the Select task.

// Step 1: Open the patient intake form page in the Zylker Patient Management application using the Open URL task
openURL("https://creatorapp.zoho.com/zylker/patient-management#Form:patient_intake", "same window");
// Step 2: Select "Follow-up" from the Appointment Type dropdown by its visible text
select(ui.zylker.appointment-type-dropdown, "Follow-up", select.TEXT);

where:

"https://creatorapp.zoho.com/zylker/patient-management#Form:patient_intake"URL of the patient intake form in the Zylker Patient Management application.
"same window"Opens the form in the window already running the test.
ui.zylker.appointment-type-dropdownStored locator for the Appointment Type dropdown on the intake form.
"Follow-up"Visible text of the appointment type option to select.
select.TEXTSelects the option by matching its visible text.

4. Use cases

Scenario 1: Selecting a strap variant and confirming it's added to the cart

An online watch store allows customers to personalize their purchase by choosing a strap material before adding the product to the cart. Each strap option represents a different product variant, and the selected variant determines the item that is added to the order.

To ensure this workflow functions correctly, a tester uses Zoho QEngine to automate the validation. The test verifies that selecting the Leather strap updates the selected variant correctly and allows the customer to add the item to the cart successfully. If the dropdown selection fails, the wrong variant may be added to the order, or the add to cart action may not proceed as expected.

Steps

  1. Open the Diver Chronomat product page in the same window.
  2. Select the option at index 1 in the Strap Material dropdown by its position.
  3. Add the product to the cart.
  4. Confirm the cart success message is shown.

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 option at index 1 in the Strap Material dropdown by its position
select("select[data-zs-attribute-name='Strap Material']", "1", select.INDEX);
// Step 3: Add the selected variant to the cart using the Click task
click(".theme-product-qty-and-add-cart");
// Step 4: Confirm the cart success message appears using the Assert Visible task
assertVisible(".theme-cart-add-success-message");

Scenario 2: Selecting a shipping country by value and confirming the selection

During checkout, an online watch store asks customers to choose their shipping country from a dropdown. The country names shown on screen, such as "United States," don't always match what the page actually submits behind the scenes, since the underlying value attribute can differ from the visible label.

A tester needs to confirm that choosing a country by its submitted value, rather than its visible text, correctly updates the dropdown before checkout proceeds. If this selection doesn't register properly, the order could be shipped against the wrong country code, even though the customer sees the correct country name on screen.

Steps

  1. Store the value attribute for United States in a variable.
  2. Open the checkout page in the same window.
  3. Select the stored value from the shipping country dropdown by its value attribute.
  4. Confirm the dropdown reflects the selection.

Implementation

// Step 1: shippingCountry holds the value attribute submitted for United States, since the dropdown's underlying value differs from the country name shown on screen
shippingCountry = "US";
// Step 2: 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 3: Select the stored country from the shipping dropdown by its value attribute
select(ui.zwatch.checkout-dropdown, shippingCountry, select.VALUE);
// Step 4: Confirm the shipping dropdown reflects the selection using the Assert Selected task
assertSelected(ui.zwatch.checkout-dropdown);

Scenario 3: Selecting a leave type in an HR web app

Consider an organization that uses a Zoho Creator app called Meridian Payroll to handle its employee leave request process. Employees submit leave requests through a form that includes a Leave Type dropdown offering Sick, Casual, and Earned options, and the type selected determines how the request is categorized and deducted from the employee's leave balance.

A tester needs to confirm that selecting the Earned option in this dropdown works correctly before the form is submitted. If the dropdown selection fails silently, a request could be submitted under the wrong leave type, leading to incorrect balance deductions or approval routing.

Steps

  1. Open the leave request form page in the Meridian Payroll web app.
  2. Select "Earned" from the Leave Type dropdown by its visible text.
  3. Submit the form.

Implementation

// Step 1: Open the leave request form page in the Meridian Payroll web app using the Open URL task
openURL("https://meridianpayroll.zohocreatorportal.com/leave-request", "same window");
// Step 2: Select "Earned" from the Leave Type dropdown by its visible text
select(ui.meridianpayroll.leave-type-dropdown, "Earned", select.TEXT);
// Step 3: Submit the form using the Click task
click(ui.meridianpayroll.submit-button);

5. Points to note

  1. Use the Select task only with dropdown fields. For checkboxes, use the Check or Uncheck task instead.
  2. select.INDEX uses zero-based indexing, where 0 represents the first option.
  3. select.VALUE matches the option's underlying value attribute, which can differ from the visible text. Inspect the option element in the page's DOM if the value attribute isn't already known.
  4. Use select.VALUE when a test needs to validate the exact value submitted by the application. Matching by visible text alone may not detect cases where the displayed label is correct but the underlying value attribute is incorrect.
  5. Verify the selected option using an assertion task, such as Assert Selected, instead of assuming the selection was successful.
  6. Prefer logical locators, such as field labels or names, over raw full XPath strings when locating the dropdown.
  1. Deselect
  2. Check
  3. Uncheck
  4. Clear
  5. Upload
  6. Assert Selected

Previous

Select is the first task covered in the Form Actions group. You may want to start with the Form Actions overview to see the full set of tasks in this group.

7. What's next

Now that you've learned how to select an option from a dropdown using the Select task, learn how to remove a previously selected option from a dropdown using the Deselect task.