I have write a script for read input data from excel file,but gives me error into sendkeys where i use getNumericCellValue. Please help. This is my code
FileInputStream file = new FileInputStream(new File ("C:\\Documents and Settings\\Deepa\\Desktop\\AMC test cases.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheet("Clinic Basic info");
WebElement creat_new_website = driver.findElement(By.className("createnew"));
creat_new_website.click();
driver.findElement(By.id("cname")).sendKeys(sheet.getRow(2).getCell(4).getStringCellValue());
//driver.findElement(By.xpath("/html/body/div[4]/div[4]/div[12]/form/div/div[1]/div[3]/div[2]/div/button")).click();
//driver.findElement(By.xpath("/html/body/div[4]/div[4]/div[12]/form/div/div[1]/div[3]/div[2]/div/ul/li[7]/a")).click();
driver.findElement(By.id("caddress")).sendKeys(sheet.getRow(4).getCell(4).getStringCellValue());
driver.findElement(By.id("clocality")).sendKeys(sheet.getRow(5).getCell(4).getStringCellValue());
driver.findElement(By.id("ccity")).sendKeys(sheet.getRow(6).getCell(4).getStringCellValue());
driver.findElement(By.id("cstate")).sendKeys(sheet.getRow(7).getCell(4).getStringCellValue());
driver.findElement(By.id("cpincode")).sendKeys(sheet.getRow(8).getCell(4).getNumericCellValue());
driver.findElement(By.id("ccountry")).sendKeys(sheet.getRow(9).getCell(4).getStringCellValue());
driver.findElement(By.id("curl")).sendKeys(sheet.getRow(10).getCell(4).getStringCellValue());
尝试
x.sendKeys(String.valueOf(someNumber))
As the error message mentions, sendKeys()
receives String
as parameter. To send double
you need to convert it into String
. The simplest ways are adding toString
driver.findElement(By.id("cpincode")).sendKeys(sheet.getRow(8).getCell(4).getNumericCellValue().toString());
Or using String.valueOf
driver.findElement(By.id("cpincode")).sendKeys(String.valueOf(sheet.getRow(8).getCell(4).getNumericCellValue()));
最简单的方法是将完整的Excel工作表列和行格式转换为字符串
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.