sendKeys and Type - Selenium IDE
sendkeys (target, text) and type (target, text) - Selenium IDE command
TYPE Command
TYPE sets the value of an input field, as though you typed it in. Can also be used to set the value of combo boxes, check boxes, etc. In these cases, value should be the value of the option selected, not the visible text. Chrome only: If a file path is given it will be uploaded to the input (for type=file). XPath locators are supported, too.
JavaScript character escape sequences (e. g. "\n")
If the internal variable !StringEscape is set to true (this is the default), then escape sequences like "\r\n" (new line) or "\t" (tab) are interpreted as escape sequence. If store | false | !stringescape is used, then they are interpreted literally. Setting it to false can be useful, for example, for sending file paths like "c:\test\note.txt" (note the \n and \t in this string!). This RPA forum post has more details.
-
List of Javascript escape sequences:
- Horizontal Tab is replaced with \t
- Vertical Tab is replaced with \v
- Nul char is replaced with \0
- Backspace is replaced with \b
- Form feed is replaced with \f
- Newline is replaced with \n
- Carriage return is replaced with \r
- Single quote is replaced with \'
- Double quote is replaced with \"
- Backslash is replaced with \\
SENDKEYS Command
The sendKeys command simulates keystroke events on the specified element, as though you typed the value key-by-key. This simulates a real user typing every character in the specified string; it is also bound by the limitations of a real user, like not being able to type into a invisible or read only elements. This is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events. Unlike the simple "type" command, which forces the specified value into the page directly, this command will not replace the existing content.
So the sendKeys command works like the type command in the selenium IDE but there are 2 more functions in the "sendKeys" command which are not available in "type" command. Theoretically the "sendKeys" command is useful in auto complete text boxes or combo boxes which require explicit key events (but in reality you should better use XTYPE, see the comments below).
Sendkeys can send the ${KEY_ENTER} key event. This means it will kind of work same as user pressing ENTER using the keyboard. Note that we say "kind of work same" because all Selenium IDE commands operate on the Javascript level inside the browser's DOM. They do not generate native OS events. So if "sendkeys" fails, use XType. For more information see XType vs Sendkey.
If Sendkeys does not work for you, use XType!
As mentioned above, the only special key supported by our implementation of Sendkey is ${KEY_ENTER}. The original Selenium IDE also supports events like KEY_DOWN (Navigation Down), but they almost never work. That is why we do not officially support them. Instead we added XTYPE: With the XType command Ui.Vision RPA can simulate native keyboard events . In other words, XType is a much more powerful "sendkeys" command than the Javascript based Type and Sendkeys Selenium IDE commands described on this page. So if Type and Sendkeys do not work for you, make sure to try XType - it will work. See also XType vs (Selenium IDE) Type/Sendkey. Important: For desktop automation you must use XTYPE. The Sendkey and Type commands always work only inside a web page.
Difference between "type" and "sendKeys" command- Example
The examples fills in the Google search box with type, and then does a sendKey with KEY_ENTER to start the search. If you would add ${KEY_ENTER} to the TYPE command, it would just fill in the special character in the input box, but not execute it.
Command | Target | Pattern/Text |
---|---|---|
open | https://google.com/ | |
Type | id=lst-ib | Solar Cells Web Automation |
sendkeys | id=lst-ib | ${KEY_ENTER} |
If you are upgrading to RPA from the original Selenium IDE: Note that the "TypeAndWait" command is no longer needed, just as any other WaitForPageToLoad command. Ui.Vision RPA for Chrome uses implicit waiting, just like webDriver.
Note that the "Focus" command is no longer needed. With Kantu, the type, sendkey and click commands automatically set the focus on the element they fill out or click on. Just noate that the browser window in which you replay must be brought to foreground to make focus work. This is not a restriction of Kantu, but this is how the focus works: Only windows that are in the foreground can have the focus. You can use the BringBrowserToForeground command to make sure the right tab is in the foreground.
Works in
Ui.Vision RPA for Chrome Selenium IDE, Ui.Vision RPA for Firefox Selenium IDE, Firefox IDE Classic
Related Demo Macros
Demo-Autofill, Demo-Frame
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, storeText, Web Automation Extension User Manual, Selenium IDE commands, Classic Firefox Selenium IDE.
Anything wrong or missing on this page? Suggestions?
...then please contact us.