繁体   English   中英

WebElement 类型中的方法 sendKeys(CharSequence...) 不适用于 arguments (int)

[英]The method sendKeys(CharSequence...) in the type WebElement is not applicable for the arguments (int)

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;
      }
   }
}

在主要 function 我打电话

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. 在这里,我创建了一个 excelutils 并在那里定义了我的所有功能
  2. 我主要使用了 excelUtils 和传递值
  3. 我收到错误“WebElement 类型中的方法 sendKeys(CharSequence...) 不适用于 arguments (int)”
  4. TestData.getCellDataasnumber(1, 3) 将从 excel 表中获得数字 25。
  5. 试过了,错误没有解决
  6. 我该如何解决这个错误

正如错误所说,您需要一个CharSequence作为sendKeys方法的参数,而不是一个int

WebElement 类型中的方法 sendKeys(CharSequence...) 不适用于 arguments (int)

这意味着您必须将int转换为 CharSequence。 实际上,获取CharSequence的最简单方法是创建String ,因此解决方案是将int转换为String 您可以通过以下方式实现此目的:

String.valueOf(TestData.getCellDataasnumber(1, 3))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM