Home > database >  Selenium is entering 9.888888888E9 as phone number after getting it from excel
Selenium is entering 9.888888888E9 as phone number after getting it from excel

Time:11-17

I have name, number, email etc in my excel which I am retrieving using the below code

Phone number in excel is 9888888888

v=wb.getSheet(sheet).getRow(r).getCell(c).toString();

but when I run my script to enter the data, selenium is entering 9.888888888E9.
I have tried formatting the cell in excel to "Text", "Number" but it has not worked.
How do I get it to enter the number as is in the excel?

CodePudding user response:

Seleniun sendKeys() doesn't have any function to convert the text. It just passes the values into destination. You need to change the method of getting value from excel. Please try below possible solutions,

v=wb.getSheet(sheet).getRow(r).getCell(c).getStringCellValue();

or

v=wb.getSheet(sheet).getRow(r).getCell(c).getRawValue();

or

if (wb.getSheet(sheet).getRow(r).getCell(c).getCellType() == Cell.CELL_TYPE_NUMERIC) {
    v = NumberToTextConverter.toText(wb.getSheet(sheet).getRow(r).getCell(c).getNumericCellValue());
} else if (wb.getSheet(sheet).getRow(r).getCell(c).getCellType() == Cell.CELL_TYPE_STRING) {
    v = wb.getSheet(sheet).getRow(r).getCell(c).getStringCellValue();
}
  • Related