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.
Keys Parameter | Keys Parameter Type | Generated Java Code |
---|---|---|
hello | Simple string |
driver.findElement(By.id("login-form:email")).sendKeys("hello"); |
<back_space> | Special character |
driver.findElement(By.id("login-form:email")).sendKeys(Keys.BACK_SPACE); |
<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.
driver.findElement(By.id("login-form:email")).sendKeys("helloo"); driver.findElement(By.id("login-form:email")).sendKeys(Keys.BACK_SPACE); driver.findElement(By.id("login-form:email")).sendKeys(" hello"); driver.findElement(By.id("login-form:email")).sendKeys(Keys.chord(Keys.CONTROL, "a")); driver.findElement(By.id("login-form:email")).sendKeys(Keys.BACK_SPACE); driver.findElement(By.id("login-form:email")).sendKeys("bye");