我尝试从 Excel 文件中读取测试数据,并且该数据在 sendkeys 中使用。
这是我的代码,但它在 FileInputStream file = new FileInputStream (new File("C:\\Documents and Settings\\Deepa\\Desktop\\testdata.xls"));
行中给了我错误,构造函数 FileInputStream(File)
未定义。
有人可以帮助我吗?
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import jxl.Workbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.gargoylesoftware.htmlunit.javascript.host.file.File;
...
WebElement login=driver.findElement(By.cssSelector("a[data-target='#login-box']"));
login.click();
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
// Workbook wb = Workbook.getWorkbook(new File("samplefile.xls"));
FileInputStream file = new FileInputStream (new File("C:\\Documents and Settings\\Deepa\\Desktop\\testdata.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
//Workbook wBook = Workbook.getWorkbook(new File("E:\\Testdata\\ShellData.xls"));
HSSFSheet sheet = workbook.getSheetAt(0);
//get sheet
// jxl.Sheet Sheet = wBook.getSheet(0);
int i;
//Now in application i have given my Username and Password input in following way
driver.findElement(By.id("uname_h")).sendKeys((CharSequence[]) Sheet.getCell(0, i));
driver.findElement(By.id("password_h")).sendKeys((CharSequence[]) Sheet.getCell(1, i));
driver.findElement(By.id("health_btn")).click();
最佳答案
问题是您尝试使用确实未定义的 com.gargoylesoftware.htmlunit.javascript.host.file.File
实例化 FileInputStream
。如果您需要该导入,那么您应该将有问题的行更改为
FileInputStream file = new FileInputStream (new java.io.File("C:\\Documents and Settings\\Deepa\\Desktop\\testdata.xls"));
关于java - 如何在selenium中读取excel中的测试数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37024082/