Textbox restricts input of certain characters but sendKeys and setValue can override this function?

Our app has a login using mobile number feature and the textbox restricts input to only numbers. Using an actual device or an emulator, I am unable to input letters, spaces, or special characters. However, when using automation tests, both sendKeys and setValue are able to input the illegal characters.

Is there a reason for this? And is there another way for me to test field validation for my automated tests?

use keyboard and type your text to reproduce 100% user behavior.

  1. tap on input
  2. keyboard will open and use:
driver.getKeyboard().sendKeys("my_test_text");
1 Like

Thanks! It’s getting the job done, but I’m getting a warning that getKeyboard().sendKeys() is deprecated. Is there another possible way?

Update: The documentation for getKeyboard().sendKeys said to look in the Actions class and I found a way.
driver.findElement(locator).click();
Actions a = new Actions(driver);
a.sendKeys(text);
a.perform();

Thanks!

Th

1 Like

did not know. thanks.

1 Like