![](/img/trans.png)
[英]The method sendKeys(CharSequence…) in the type WebElement is not applicable for the arguments (double)
[英]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));
}
}
正如错误所说,您需要一个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.