how to enter numeric value into textbox in webdriver

主宰稳场 提交于 2021-01-21 06:15:10

问题


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);
    }

回答1:


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

element.sendKeys(String.valueOf(number))



回答2:


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




回答3:


public void sendKeysINTByJS(WebDriver driver, WebElement element, int attributeValue){
    JavascriptExecutor js = ((JavascriptExecutor) driver);
    js.executeScript("arguments[0].setAttribute('value','"+attributeValue+"');", netQtty);
}



回答4:


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);


来源:https://stackoverflow.com/questions/25976058/how-to-enter-numeric-value-into-textbox-in-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!