如何使用SeleniumWebDriver将控制台输出与excel工作表数据进行比较?

wj8zmpe1  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(183)

我已将表的元素检索到控制台窗口,并希望将输出与excel工作表中的数据进行比较。有人能帮我吗?

// To locate table.
    WebElement mytable = driver.findElement(By.xpath("//*[@id=\ejSearchResultTable\"]"));
    // To locate rows of table.
    List<WebElement> rows_table = mytable.findElements(By.tagName("tr"));
    // To calculate no of rows In table.
    int rows_count = rows_table.size();
    // Loop will execute till the last row of table.
    for (int row = 0; row < rows_count; row++) {
        // To locate columns(cells) of that specific row.
        List<WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
        // To calculate no of columns (cells). In that specific row.
        int columns_count = Columns_row.size();
        System.out.println("Number of cells In Row " + row + " are " + columns_count);
        // Loop will execute till the last cell of that specific row.
        for (int column = 0; column < columns_count; column++) {
            // To retrieve text from that specific cell.
            String celtext = Columns_row.get(column).getText();
            System.out
                    .println("Cell Value of row number " + row + " and column number " + column + " Is " + celtext);
        }

    }

从excel读取数据:

String path = "C:\\Users\\Desktop\\ExportExcel.xlsx";  
FileInputStream fis = new FileInputStream(path);  
Workbook workbook = new XSSFWorkbook(fis);  
Sheet sheet = workbook.getSheetAt(0);  
for (int i=0; i<Rowcount+1 ; i++)
{
Row row = sheet.getRow(i);
for (int j = 0; j < row.getLastCellNum(); j++)
{
System.out.println("Cell Value of row number " + i + " and column number " + j+ " Is " + row.getCell(j).getStringCellValue());
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题