Send Keys task

Send Keys task

In a nutshell

The Send Keys task sends a sequence of keystrokes to a web element during test execution. It can combine typed text with special keys such as Tab, Enter, or Delete in a single action. This triggers keyboard-driven behavior, which differs by simulating actual keystrokes rather than setting a field's value directly, such as submitting a form with Enter or moving focus to the next field with Tab.

1. Overview

The Send Keys task sends a sequence of keystrokes to a web element, registered by the browser as genuine keyboard input rather than a value set directly using the Set Value task. It's commonly used to automate scenarios such as submitting a form by pressing Enter, moving between fields with Tab, or triggering a live suggestion that only appears while typing.

Each call takes an array combining plain text, such as a username or password, with special key constants, such as keys.ENTER or keys.TAB. The values are sent to the element in the order they are listed.

2. Syntax

sendKeys(<locator>, <keys>);


ParameterData TypeDescription
locatorSTRINGIdentifies the element that should receive the keystrokes.

Note: Locators can be found by <manually inspecting> the webpage for the element, or by using an element already saved through a <recording> session. <Learn more about Elements>
keysARRAYLISTSequence of keystrokes to send to the element, sent in the order listed. Each item is either a plain text string, sent as literal characters, or a special key constant, such as keys.ENTER, keys.TAB, or keys.DELETE. See Supported key constants for the complete list.

Supported key constants:

ADD, ALT, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, BACK_SPACE, CANCEL, CLEAR, COMMAND, CONTROL, DECIMAL, DELETE, DIVIDE, DOWN, END, ENTER, EQUALS, ESCAPE, HELP, HOME, INSERT, LEFT, LEFT_ALT, LEFT_SHIFT, META, MULTIPLY, NULL, PAGE_DOWN, PAGE_UP, PAUSE, RETURN, RIGHT, SEMICOLON, SEPARATOR, SHIFT, SPACE, SUBTRACT, TAB, UP.

3. Examples

Example 1: Submitting a search using the enter key

Submit a search by sending the Enter key after entering a search term.

// Open the ZWatch Commerce home page using the <Open URL> task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Click the search icon to reveal the search input using the <Click> task
click(".theme-search");
// Enter a search term using the <Set Value> task
setValue("[data-search-input]", "Chrono 44");
// Submit the search by sending the Enter key using the Send Keys task
sendKeys("[data-search-input]", [keys.ENTER]);
// Confirm the results heading reflects the search term using the Assert Text task
assertText(".search-results-heading", "Results for Chrono 44", errorhandling.STOP_ON_ERROR);

where:

"https://zwatch.zohocommerce.com/"ZWatch Commerce home page URL.
"same window"Opens the page in the window already running the test.
.theme-searchLocator for the search icon.
[data-search-input]Locator for the search box.
"Chrono 44"Search term entered into the search box.
keys.ENTERSubmits the search, the same as pressing Enter.
.search-results-headingLocator for the results heading.
errorhandling.STOP_ON_ERRORStops the test if the results heading doesn't match.

Example 2: Filling and submitting a login form in one call

Fill the username and password fields and submit the form in a single Send Keys call, moving between fields with Tab and submitting by sending Enter.

// Open the login page using the <Open URL> task
openURL("https://www.<website_name>.com/<login_page>", "same window");
// Fill in the username and password fields and submit the form using the Send Keys task
sendKeys(ui.<login_page>.<username_field>, ["chris.morgan", keys.TAB, "SecurePass123", keys.ENTER]);
// Confirm the account page loads using the <Assert Visible> task
assertVisible(ui.<login_page>.<account_dashboard>, errorhandling.STOP_ON_ERROR);

where:

"https://www.<website_name>.com/<login_page>"Login page URL.
"same window"Opens the page in the window already running the test.
ui.<login_page>.<username_field>Locator for the username field, where the key sequence begins.
["chris.morgan", keys.TAB, "SecurePass123", keys.ENTER]Enters the username, uses Tab to move focus to the password field, then enters the password and uses Enter to submit the form.
ui.<login_page>.<account_dashboard>Locator for the account dashboard, shown after a successful login.
errorhandling.STOP_ON_ERRORStops the test if the account dashboard doesn't load.

Example 3: Dismissing a search suggestions panel using Escape

Close the search suggestions panel by sending Escape after entering a partial search term, without selecting an option.

// Open the search page using the <Open URL> task
openURL("https://www.<website_name>.com/<search_page>", "same window");
// Enter a partial search term using the <Set Value> task
setValue(ui.<search_page>.<search_field>, "Chro");
// Press Escape to close the suggestions panel using the Send Keys task
sendKeys(ui.<search_page>.<search_field>, [keys.ESCAPE]);
// Confirm the suggestions panel is closed using the <Get Count> task
suggestionsCount = getCount(ui.<search_page>.<suggestions_panel>);
if (suggestionsCount != 0)
{
throwError("Suggestions panel did not close after pressing Escape");
}

where:

"https://www.<website_name>.com/<search_page>"Search page URL.
"same window"Opens the page in the window already running the test.
ui.<search_page>.<search_field>Locator for the search field.
"Chro"Partial search term entered into the search field.
keys.ESCAPECloses the suggestions panel without selecting an option.
ui.<search_page>.<suggestions_panel>Locator for the suggestions panel.
suggestionsCountVariable storing the number of suggestions panels found after pressing Escape.

Example 4: Moving between fields with tab in a Recruitment Portal application

Populate the First Name and Last Name fields on the Zoho Creator Recruitment Portal application form by navigating between fields with Tab, using a single Send Keys call.

// Open the candidate application form in the Recruitment Portal application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/recruitment-portal#Form:New_Application", "same window");
// Enter the first and last names, moving between fields with Tab, using the Send Keys task
sendKeys(ui.recruitmentportal.first-name-field, ["Jordan", keys.TAB, "Lee"]);
// Confirm both fields hold the entered values using the <Assert Value> task
assertValue(ui.recruitmentportal.first-name-field, "Jordan", errorhandling.STOP_ON_ERROR);
assertValue(ui.recruitmentportal.last-name-field, "Lee", errorhandling.STOP_ON_ERROR);

where:

"https://creatorapp.zoho.com/<orgname>/recruitment-portal#Form:New_Application"Candidate application form URL.
"same window"Opens the form in the window already running the test.
ui.recruitmentportal.first-name-fieldLocator for the First Name field, where the key sequence begins.
["Jordan", keys.TAB, "Lee"]Fills the first name, moves to the Last Name field, then fills it.
ui.recruitmentportal.last-name-fieldLocator for the Last Name field.
errorhandling.STOP_ON_ERRORStops the test if either field doesn't hold the entered value.

4. Use cases

Scenario 1: Confirming a search submitted with enter returns relevant results

Shoppers often press Enter to submit a search rather than clicking a separate search button, and the search needs to respond the same way either action is taken.

A tester uses Zoho QEngine to verify that submitting a search for Chrono 44 on the ZWatch Commerce home page with the Enter key returns matching results. This confirms the search behaves consistently regardless of how it is submitted.

Steps

  1. Open the ZWatch Commerce home page in the same window.
  2. Click the search icon to reveal the search input.
  3. Enter the search term "Chrono 44."
  4. Submit the search by sending the Enter key.
  5. Confirm the results heading reflects the search term.

Implementation

// Step 1: Open the ZWatch Commerce home page in the same window using the <Open URL> task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the search icon to reveal the search input using the <Click> task
click(".theme-search");
// Step 3: Enter a search term using the <Set Value> task
setValue("[data-search-input]", "Chrono 44");
// Step 4: Submit the search by sending the Enter key using the Send Keys task
sendKeys("[data-search-input]", [keys.ENTER]);
// Step 5: Confirm the results heading reflects the search term using the Assert Text task
assertText(".search-results-heading", "Results for Chrono 44", errorhandling.STOP_ON_ERROR);

Scenario 2: Confirming a registration form can be completed using tab

New customers filling out a registration form often move between fields by pressing Tab rather than clicking each field. The form should respond correctly to this keyboard navigation and submit successfully when Enter is pressed.

A tester uses Zoho QEngine to verify that users can enter their name, email address, and password, navigate between fields using Tab, and submit the registration form with Enter to create an account.

Steps

  1. Open the registration form in the same window.
  2. Enter the name, email, and password fields in sequence, using tab to move between them.
  3. Submit the form to create the account.
  4. Confirm the account is created.

Implementation

// Step 1: Open the registration form in the same window using the <Open URL> task
openURL("https://www.<website_name>.com/<registration_page>", "same window");
// Step 2: Enter the name, email, and password fields, moving between them with Tab, using the <Send Keys> task
sendKeys(ui.<registration_page>.<name_field>, ["Jamie Rivera", keys.TAB, "jamie.rivera@example.com", keys.TAB, "SecurePass123"]);
// Step 3: Submit the form using the <Click> task
click(ui.<registration_page>.<submit_button>);
// Step 4: Confirm the account is created using the <Assert Visible> task
assertVisible(ui.<registration_page>.<account_created_message>, errorhandling.STOP_ON_ERROR);

Scenario 3: Confirming a dropdown can be navigated using arrow keys and enter

Consider a Recruitment Portal application built on Zoho Creator that job candidates use to submit applications. Candidates sometimes navigate the Job Category dropdown using arrow keys and Enter rather than clicking an option directly.

A tester uses Zoho QEngine to verify that pressing the Down Arrow key to move through the options, followed by Enter to select one, chooses the correct Job Category. This confirms that candidates can complete the selection using only the keyboard and submit their application under the intended category.

Steps

  1. Open the candidate application form in the Recruitment Portal application.
  2. Click the Job Category dropdown to give it focus.
  3. Press the down arrow key to move to the next option, then Enter to confirm it.
  4. Confirm the dropdown reflects the selected category.

Implementation

// Step 1: Open the candidate application form in the Recruitment Portal application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/recruitment-portal#Form:New_Application", "same window");
// Step 2: Click the Job Category dropdown to give it focus using the Click task
click(ui.recruitmentportal.job-category-dropdown);
// Step 3: Press the down arrow key to move to the next option, then Enter to confirm it, using the Send Keys task
sendKeys(ui.recruitmentportal.job-category-dropdown, [keys.ARROW_DOWN, keys.ENTER]);
// Step 4: Confirm the dropdown reflects the selected category using the Assert Value task
assertValue(ui.recruitmentportal.job-category-dropdown, "Engineering", errorhandling.STOP_ON_ERROR);

5. Points to note

  1. Use Send Keys only when the interaction depends on genuine keyboard events, not just the final value. For a plain value entry with no keyboard-driven behavior, use <Set Value> instead.
  2. Keys are sent to the element in the order they appear in the array. Mixing plain text and special key constants in one call sends them as a single continuous sequence.
  3. Follow the Send Keys task with an appropriate assertion task to verify the expected result. Use <Assert Text> to verify visible page content, such as a confirmation message, and <Assert Value> to verify the value of a form field, such as a selected drop down option.
  4. Send Keys requires an editable element, such as an input, text area, or content-editable element. Prefer ID or CSS selectors for locating the element, and use XPath only when no unique ID or CSS selector is available.
  1. Set Value
  2. Click
  3. Assert Value

Previous

Before learning about the Send Keys task, ensure you have learned how to right-click an element using the <Right Click> task.

7. What's next

Now that you've learned how to send keystrokes to an element using the Send Keys task, learn how to hover over an element using the <Hover> task.