import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class ExcelUtils {
private XSSFSheet ExcelWSheet;
private XSSFWorkbook ExcelWBook;
//Constructor to connect to the Excel with sheetname and Path
public Excelutils(String Path, String SheetName) throws Exception {
try {
// Open the Excel file
FileInputStream ExcelFile = new FileInputStream(Path);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
} catch (Exception e) {
throw (e);
}
}
//This method is to set the rowcount of the excel.
public int excel_get_rows() throws Exception {
try {
return ExcelWSheet.getPhysicalNumberOfRows();
} catch (Exception e) {
throw (e);
}
}
//This method to get the data and get the value as number.
public double getCellDataasnumber(int RowNum, int ColNum) throws Exception {
try {
double CellData =
ExcelWSheet.getRow(RowNum).getCell(ColNum).getNumericCellValue();
System.out.println("The value of CellData " CellData);
return CellData;
} catch (Exception e) {
return 000.00;
}
}
}
And in Main function i am calling
import Utils.ExcelUtils;
public class getInt extends OpenDriver {
@Test
public void getInt() throws Exception {
ExcelUtils TestData = new ExcelUtils("D:\\Selenium Automation\\TestData\\user.xlsx",
"User");
driver = LaunchBrowser();
driver.findElement(By.xpath("//input[@name='capacity']")).sendKeys(TestData.getCellDataasnumber(1, 3));
}
}
- here i have created a excelutils and defined all my functions overthere
- in main i have used excelUtils and passing value
- I am getting error "The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int)"
- TestData.getCellDataasnumber(1, 3) will get number 25 from excel sheet.
- tried, error not fixing
- How can i fix this error
CodePudding user response:
Just as the error says, you need a CharSequence
as the parameter of the sendKeys
method, instead of an int
:
The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int)
This means that you have to convert the int
to a CharSequence. In practice, the simplest way to get a CharSequence
is to create a String
, so the solution is to convert the int
to a String
. You can achieve this in the following way:
String.valueOf(TestData.getCellDataasnumber(1, 3))