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 Kantu 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}

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}

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)

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

${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}

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!

Command Target Pattern/Text
open https://a9t9.com/
XType ${KEY_CTRL+KEY_S}
XType New-file-name${KEY_ENTER}
echo Page saved

Works in

Kantu for Chrome and Kantu for Firefox with the RealUser XModule installed.

Related Demo Macros

Demo-XType, Demo-XClick

The ready-to-import-and-run source code of all demo macros can be found in the Github repository testmacros folder.

See also

XClick, XMove, XModules User Manual

Anything wrong or missing on this page? Suggestions?

...then please contact us.

Kantu Selenium IDE for Chrome and Firefox - Web Test Automation
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.