Entering Special Keys Into A Text Field

When testing web applications, Silk4J offers the following recording modes:
  • Silk Test, which allows you to record Silk4J locators.
  • WebDriver, which allows you to record WebDriver locators. This recording mode is not supported when recording against Internet Explorer.

In this topic, we will describe how you can enter special keys by adding code to a script that has been recorded by using the WebDriver recording mode. For information on handling special keys when using the Silk Test recording mode, you can refer to the API documentation of the typeKeys method.

When using the WebDriver recording mode, special keys need to be placed between angled brackets. For example <back_space> or <enter>.

All special keys in the class org.openqa.selenium.Keys.java are allowed in Silk4J. The values of the keys are case-insensitive.

Note: In all supported browsers except Mozilla Firefox, you can send multiple special keys or key chords in a single call to the sendKeys method. However, to create cross-browser scripts that will also work on Mozilla Firefox, Micro Focus recommends sending only a single string, special key, or key chord at a time with each call to sendKeys.


When using the sendKeys method on a text field during recording, the following sample parameter values for the Keys parameter work on all browsers:
Keys Parameter Keys Parameter Type Generated Java Code
hello Simple string
<back_space> Special character
<control+a> Chord
driver.findElement(By.id("login-form:email")).sendKeys(Keys.chord(Keys.CONTROL, "a"));

For example, let us assume we have recorded the following actions.

As there are only single special characters or key chords in each call to the sendKeys method, these actions replay on all supported browsers, including Mozilla Firefox.

The corresponding generated code, for example in Java, looks like the following:
driver.findElement(By.id("login-form:email")).sendKeys(" hello");
driver.findElement(By.id("login-form:email")).sendKeys(Keys.chord(Keys.CONTROL, "a"));