I have an input on a form I wish to test using Selenium. I have a form input of type number as below
<input required type="number" class="form-control" id="number" name="number" placeholder="Number" step="1" min="0" max="4">
I wish to test this form by using Selenium Chrome Driver. I have the following code
WebElement number = driver.findElement(By.id("number"));
number.sendKeys("2");
I have also tried
WebElement number = driver.findElement(By.id("number"));
int numberInt = 2;
number.sendKeys(Integer.toString(numberInt));
But get the following error and stack trace:
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
Any ideas how I can send a value of 2 to my input field?