Home > Mobile >  The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int
The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int

Time:08-24

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));
    }
}
  1. here i have created a excelutils and defined all my functions overthere
  2. in main i have used excelUtils and passing value
  3. I am getting error "The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int)"
  4. TestData.getCellDataasnumber(1, 3) will get number 25 from excel sheet.
  5. tried, error not fixing
  6. 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))
  • Related