我无法在Webdriver中使用Java在数字字段中保留数值

时间:2013-01-04 06:46:13

标签: java webdriver selenium-webdriver

我无法在Webdriver中使用Java在数字字段中保留数值。我已经尝试了Stackoverfolw问题中提供的答案 -

Java : For String values we use the command sendKeys("String"); Similarly what is the command for posting a numeric data to the numeric field

请在我写的答案部分找到更多详细信息。

driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys(String.valueOf(12345));
Thread.sleep(5000);
new Actions(driver).sendKeys(driver.findElement(By.id(OR.getProperty("AccTax_ID"))), 
"").perform();

这是一个字段,就像明智一样,我有更多的数字字段。任何人都可以帮我解决这个问题。将不胜感激。

2 个答案:

答案 0 :(得分:0)

将整数值发送到整数字段与将文本值发送到文本字段相同。

driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys("12345");

OR

如果您在变量

中保存了任何整数值
int value=12345;
driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys(""+value);

答案 1 :(得分:0)

请勿使用Thread.sleep();

首先你必须启用元素。然后将值放在该字段上。

试试这个:

driver.findElement(By.id(OR.getProperty("AccTax_ID"))).click();
driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys(String.valueOf(12345));
driver.findElement(By.id(OR.getProperty("AccTax_ID"))).sendKeys(Keys.TAB);