问题
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