Java 运行数据驱动的
当在给定字段中执行数据驱动时,代码将用于其实现,而不是运行代码的下一步Java 运行数据驱动的,java,selenium-webdriver,apache-poi,Java,Selenium Webdriver,Apache Poi,当在给定字段中执行数据驱动时,代码将用于其实现,而不是运行代码的下一步 //poi WebElement searchbox = driver.findElement(By.name("simcard")); try { FileInputStream file = new FileInputStream(new File("C:\\paulo.xls")); HSSFWorkbook workbook = new HSSFWorkbook(
//poi
WebElement searchbox = driver.findElement(By.name("simcard"));
try
{
FileInputStream file = new FileInputStream(new File("C:\\paulo.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
for (int i=1; i <= sheet.getLastRowNum(); i++)
{
String simcard = sheet.getRow(i).getCell(0).getStringCellValue();
searchbox.sendKeys(simcard);
searchbox.submit();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
}
workbook.close();
file.close();
}
catch (FileNotFoundException fnfe)
{
fnfe.printStackTrace();
}
catch (IOException ioe)
{
ioe.printStackTrace();
有人经历了这个问题?解决了,我的代码中有一些错误,因为修复程序没有运行代码的下一步。好的,那么它做什么呢?你有错误吗?向我们显示错误消息。为了有人能够帮助你,我们需要知道你期望这个程序做什么,以及它实际上做了什么。当然,我们至少需要看到代码行中发生了什么(尽管这并不总是足够的)。findElement应该放在代码中的什么位置?在try-catch块之后?另外,我建议在这里进行数据驱动测试。@jameslarge什么都没有发生,这就是奇怪的,Logcat中没有任何内容,控制台上没有任何内容,屏幕上没有错误,它只是冻结,就好像他被暂停了一样。代码似乎工作正常。。。看来问题出在别的地方了。。。你能分享你的工作簿吗。。。?
driver.findElement(By.xpath("/html/body/table/tbody/tr[4]/td/div/form/table/tbody/tr[2]/td/center/table/tbody/tr[19]/td/a[1]/img")).click();