RE: Using Sendkeys accept String data and not Ints

Answered

I had a problem using sendKeys when I was pulling data from an excel spreadsheet if the data was numeric.

I now see that sendKeys only works for strings.   I’m using the following code to get data from excel

//This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num

public static String getCellData(int RowNum, int ColNum) throws Exception{

try{

Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);

String CellData = Cell.getStringCellValue();

return CellData;

}catch (Exception e){

return"";

}

}
// Then I use

String Phone = ExcelUtils.getCellData(1,11);
// followed by

txtPhone.sendKeys(strPhone);

What I don’t understand is , if I’m  saying that strPhone is a type String and the system doesn’t give me a type mismatch error why is sendKeys thinking its an int?

I can enter the data in excel as ‘3032229898 telling excel its a string and that works. Is there a better way?

on November 4, 2014.
Add Comment
1 Answers
Best answer

Hi Richard,

Try this:


public static String getCellData(int RowNum, int ColNum, String SheetName ) throws Exception{

String sValue = "";

int iValue = 0;

try{

if(Cell.getCellType() == Cell.CELL_TYPE_NUMERIC){

iValue = (int) Cell.getNumericCellValue();

sValue = Utils.convertToStr(iValue);

}else if(Cell.getCellType() == Cell.CELL_TYPE_FORMULA){

//Your Code

}else if(Cell.getCellType() == Cell.CELL_TYPE_BLANK){

//Your Code

}else{

sValue = Cell.getStringCellValue();

}

}catch (Exception e){

Log.error("Class ExcelUtil | Method getCellData | Exception desc : "+e.getMessage());

}

return sValue;

}

public static String convertToStr(int iValue)throws Exception{

try{

String sValue;

sValue = String.valueOf(iValue);

return sValue;

}catch(Exception e){

Log.error("Class Utils | Method convertToStr | Exception desc : "+e.getMessage());

throw (e);

}

}

Professor Answered on October 30, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.