-1

How to enter numeric value into textbox in Selenium webdriver. The code is below: sendKeys() method is not working for numeric value, is there any alternative command for the integers.

@FindBy(id="toolbox-options-key")
private WebElement BillingRateTextBox;

    public void createNewBill(String billingRate)
    {
        BillingRateTextBox.sendKeys(10);
    }
SiKing
  • 10,003
  • 10
  • 39
  • 90
Nages
  • 763
  • 1
  • 9
  • 12

6 Answers6

12

You need to convert the Integer to String and pass them to sendKeys like this:

element.sendKeys(String.valueOf(number))
Zoe
  • 27,060
  • 21
  • 118
  • 148
Ant's
  • 13,545
  • 27
  • 98
  • 148
1

running this:

paris.FindElementByTag("input").SendKeys ("4")

will APPEND 4 to the current input content.

paris.FindElementByTag("input").Clear

will put a 0 in the input

then SendKeys ("4") will work

sandoz
  • 21
  • 6
0
public void sendKeysINTByJS(WebDriver driver, WebElement element, int attributeValue){
    JavascriptExecutor js = ((JavascriptExecutor) driver);
    js.executeScript("arguments[0].setAttribute('value','"+attributeValue+"');", netQtty);
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
0

When an input box is of integer type, here is the solution for you to be able to pass integer values into this integer type input box:

{integer input box element ID}.Click();
{integer input box element ID}.SendKeys(""+99999);
SandPiper
  • 2,816
  • 5
  • 30
  • 52
0

Another solution you can try if the input box is of integer type is:

@FindBy(id="toolbox-options-key")
private WebElement BillingRateTextBox;

    public void createNewBill(String billingRate)
    {
        BillingRateTextBox.sendKeys(int(10));
    }
Striezel
  • 3,693
  • 7
  • 23
  • 37
0

How to enter numeric value into textbox in webdriver :

ExFactory_Price_per_Pack.sendKeys(String.valueOf(100));
James Risner
  • 5,451
  • 11
  • 25
  • 47