XType ("text")

The XType command allows you to send real user keyboard events to web page elements and even simulate global keyboard shortcuts such as the famous Ctrl+C/Ctrl+V (copy and paste) or "Alt+F4" (close current window). With XType you can be sure that a web app reacts 100% the same way as if a real human user would type the text.


The second option in this tutorial uses XClick | (image of select box) to find the JQuery select box on the page and give it the focus. Then the macro uses the XType command with the ${KEY_DOWN}${KEY_DOWN}${KEY_ENTER} key sequence to select an entry. The same sequence send with the classic Selenium-IDE Sendkeys command would fail, as the select box reacts only to native keyboard events.

What is the difference between XType and the Selenium IDE Type and Sendkey commands?

The classic Type or Sendkeys command as used by Ui.Vision RPA and any other Selenium IDE or browser automation tool does not simulate real keystrokes. Instead they operate on the Javascript level inside the browser DOM. This the reason why these commands all require a locator to identify a web page element, and then send Javascript events to this element, or sometimes even just set the text property of this element. On simple websites this is often enough and works well. But on modern complex websites (e. g. Google Gmail, Google Spreadsheet, Microsoft Office 365, Facebook, Instagram,...) it is often difficult to find the right element locator in the first place. And even if you found the right locator, it can happen that the website logic swallows the Javascript keystroke event and it never reaches the right target element. In addition, if you want to automate websites with canvas elements (e. g. drawing apps like Sketchpad.io and most online games) it is impossible to find a locator for the classic type/sendkey command.

In contrast the XType avoids all these problems by simulating real user keystroke events. This also means there is no need to have a locator. Just like when you type on a real physical keyboard, whatever element has the focus receives the keyboard input. You can use "XClick | (xpath locator)" or "XClick | image of element" to set the focus to the right place, before you send the keystroke sequence with XType.

This sounds great, so why would one use the classic Type or Sendkey command at all?

Well, XType (just like the other real user commands XClick and XMove) has one drawback: As it simulates real user input, it requires an unlocked user desktop to simulate events, and the browser window has to be in the foreground. This is the same requirement that you would have for a human operator - no human can type something if the desktop has been locked. So here the classic type/sendkey commands wins: It works just fine with Chrome or Firefox running in the background as everything happens just inside the web browser.

So we recommend to first test if your text input works with the classic type command, and if not, then use XType. It will work for sure!

The XType, XClick and XMove need the RealUser Simulation XModule to be installed.

Key Constants and Special Keys

Note that unlike the classic type command XType itself does not take a target as input. Instead, it “stupidly” sends keystrokes to whatever element has the focus. Therefore in many cases you must first send an XClick command to the place where the keystrokes should go, so the right element has the focus. This is the same as if you (as human user) first mouse-click in an input field before you start typing.

Typical usage: XType | text here ${KEY_CTRL+KEY_V} more text here ${KEY_ENTER}

Important: You need the ${KEY_XXX} notation only if you explicitly want to simulate keyboard presses. This is typically required to trigger keyboard shortcuts, such as "Ctrl+S". But for normal text input just send the text with XType | your text here. To test the XType command you can use for example http://keyboardchecker.com/ (external website).

Up to three meta keys are supported, for example XType | ${KEY_CTRL+KEY_ALT+KEY_SHIFT+KEY_F1}

Possible modifier keys (also called meta keys):
${KEY_CTRL},
${KEY_ALT} and
${KEY_SHIFT}

Special Windows and Mac modifier keys:
${KEY_WIN} (Windows Key)
${KEY_CMD} (Mac Command Key)
${KEY_META} - this key simulates ${KEY_WIN} on Windows and ${KEY_CMD} on a Mac

Standard keyboard keys:

${KEY_0}...${KEY_9} (Numbers)
${KEY_A}...${KEY_Z} (Letters)
${KEY_F1}...${KEY_F15} (Function keys)
${KEY_Num0}...${KEY_Num9} (Number keys)
${KEY_SPACE} (Space bar)

Possible special keys:
${KEY_ENTER} - this is the most used special key

${KEY_ESC} - simulates the ESCAPE key press

${KEY_TAB}
${KEY_BKSP} = ${KEY_BACKSPACE}
${KEY_DEL} = ${KEY_DELETE}

${KEY_UP}
${KEY_DOWN}

${KEY_RIGHT}
${KEY_LEFT}

${KEY_PGUP} = ${KEY_PAGE_UP}
${KEY_PGDN}= ${KEY_PAGE_DOWN}

${KEY_HOME} - return the cursor to the beginning of the line
${KEY_END} - send the cursor to the end of a document

JavaScript character escape sequences are not supported with XType, but you can replace them with the special key constants. So instead of "\r\n" use ${KEY_ENTER}.

Do you miss support for certain key sequence? Please tell us about it in the RPA forum and we will add it with future RPA software updates. In the meantime you can use the XRUN sendkeys workaround to simulate it (e. g for KEY_PLUS).

Copy and Paste

Tip: If you need to send a lot of text, store it in the !clipboard built-in variable and then paste (CTRL+V) the text into the field. This copy and paste method runs faster than sending all the text as simulated keystrokes with XType. Example:

Command Target Pattern/Text
store Long text....\nwith line breaks.... !clipboard
XClick Locator or Image (this is used to set the focus on the text box)
XType ${KEY_CTRL+KEY_A}

Related forum post: How to copy and paste text with RPA software.

XType Example

This example macro sends "Ctrl+S" to open the browser's "Save Page As" dialog. Then it sends a file name and simulates the "Enter" key. => Page saved!

We recommend to break up longer text entry sequences in two or more separate XType commands. The reason is that the short internal break between both commands makes the keystroke simulation speed more naturally. And if needed, you can add a PAUSE command between XTypes commands, or slow down the macro replay speed. Most applications and websites are not tested and designed for robotic process automation (RPA) speeds. Some work fine at high keystroke speeds, but in other cases characters may "get lost" somewhere in the message queue of the application, browser or operating system. If this happens, add some delays between the XTypes. As a rule of thumb, if you see that some characters are not recognized, slow down the text entry. You should not enter text faster than a human can type.

Command Target Pattern/Text
open https://ui.vision/
XType ${KEY_CTRL+KEY_S}
store false !stringescape
XType New-file-name
Pause 100
XType ${KEY_ENTER}
echo Page saved

Works in

Ui.Vision RPA for Chrome and Ui.Vision RPA for Firefox with the RealUser XModule installed.

XType Related RPA Forum Posts

Related Demo Macros

Demo-XType, Demo-XClick

The ready-to-import-and-run source code of all demo macros can be found in the Open-Source RPA software Github repository.

See also

Selenium IDE form filling tutorial, XClick, XMove, XModules User Manual

Anything wrong or missing on this page? Suggestions?

...then please contact us.

<em>Ui.Vision RPA</em> Selenium IDE for Chrome and Firefox - Web Test Automation

Fresh from the Ui.Vision Forum: The Latest 3 Topics. Join the discussions:

← Meet the Ui.Vision team and users in our forums.