srinuvasareddy marri
srinuvasareddy marri

Reputation: 69

Sendkeys() method in selenium webdriver

The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (double)

wd.findElement(By.id("----")).sendKeys(sheet.getRow(2).getCell(0).getNumericCellValue());

How can I get numeric cell value from Excel into sendkeys method, for string value it's working fine.

Now I am using poi jar files

Upvotes: 1

Views: 8268

Answers (3)

Dave
Dave

Reputation: 591

SendKeys requires a String object to be passed, but you're passing it a numeric value.

Try this instead:

WebElement element = null;
try {
    element = wd.findElement(By.id("----"));
    element.sendKeys(sheet.getRow(2).getCell(0).getStringCellValue());
    );
} catch (Exception e) {
    /* this is thrown if the cell contains a formula that isn't a "string Formula" */
}

Note that I've changed the getNumericCellValue() for getStringCellValue().

Upvotes: 0

sreenath
sreenath

Reputation: 499

It's simple, convert the numeric value to string. like String str = ""+5;

for your case use ""+sheet.getRow(2).getCell(0).getNumericCellValue()

i.e

wd.findElement(By.id("----")).sendKeys(""+sheet.getRow(2).getCell(0).getNumericCellValue());

In case of numeric cells, apache poi returns double value. to get the exact double values, i.e with out character 'E', convert the double value to BigDecimal and get it's String representation, like below

Double d = 1.234567E8;
String str1 = new BigDecimal(d).toString();
System.out.println(str1);

Output : 123456700 That's all

Upvotes: 1

Nilamber Singh
Nilamber Singh

Reputation: 874

since "Sendkeys()" only accept String as an argument, so if u want to pass a numeric value into sendkeys, you have to convert it into String. I'll take an example to explain this in detail.

Suppose u get "1455" from excel and u want to pass it to sendkeys then convert it into String like this:

String num = Double.toString("1455");
webElement.SendKeys(num);

Upvotes: 0

Related Questions