Selenium webdriver 如何使用selenium从excel复制特定整行

Selenium webdriver 如何使用selenium从excel复制特定整行,selenium-webdriver,apache-poi,Selenium Webdriver,Apache Poi,我在编码从excel工作表中选择特定整行并将其粘贴到Web应用程序页面时遇到问题 您可以使用rowIterator逐行读取,并根据条件选择所需的特定行 选择所需行后,使用cellIterator作为Selenium命令的输入值,以便在网页中发布这些值 使用Apache POI读取excel程序示例: package com.howtodoinjava.demo.poi; //import statements public class ReadExcelDemo { public sta

我在编码从excel工作表中选择特定整行并将其粘贴到Web应用程序页面时遇到问题

您可以使用rowIterator逐行读取,并根据条件选择所需的特定行

选择所需行后,使用cellIterator作为Selenium命令的输入值,以便在网页中发布这些值

使用Apache POI读取excel程序示例:

package com.howtodoinjava.demo.poi;
//import statements
public class ReadExcelDemo
{
    public static void main(String[] args)
    {
        try
        {
            FileInputStream file = new FileInputStream(new File("howtodoinjava_demo.xlsx"));

            //Create Workbook instance holding reference to .xlsx file
            XSSFWorkbook workbook = new XSSFWorkbook(file);

            //Get first/desired sheet from the workbook
            XSSFSheet sheet = workbook.getSheetAt(0);

            //Iterate through each rows one by one
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();

                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                    //Check the cell type and format accordingly
                    switch (cell.getCellType())
                    {
                        case Cell.CELL_TYPE_NUMERIC:
                            System.out.print(cell.getNumericCellValue() + "t");
                            break;
                        case Cell.CELL_TYPE_STRING:
                            System.out.print(cell.getStringCellValue() + "t");
                            break;
                    }
                }
                System.out.println("");
            }
            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
package com.howtodoinjava.demo.poi;
//导入语句
公共类ReadExcelDemo
{
公共静态void main(字符串[]args)
{
尝试
{
FileInputStream file=newfileinputstream(新文件(“howtodoinjava_demo.xlsx”);
//创建包含对.xlsx文件引用的工作簿实例
XSSF工作簿=新XSSF工作簿(文件);
//从工作簿中获取第一张/所需的工作表
XSSFSheet sheet=workbook.getSheetAt(0);
//逐个遍历每一行
迭代器rowIterator=sheet.Iterator();
while(roweiterator.hasNext())
{
行=行迭代器。下一步();
//对于每一行,遍历所有列
迭代器cellIterator=row.cellIterator();
while(cellIterator.hasNext())
{
Cell=cellIterator.next();
//检查相应的单元格类型和格式
开关(cell.getCellType())
{
case Cell.Cell\u类型\u数值:
System.out.print(cell.getNumericCellValue()+“t”);
打破
case Cell.Cell\u类型\u字符串:
System.out.print(cell.getStringCellValue()+“t”);
打破
}
}
System.out.println(“”);
}
file.close();
}
捕获(例外e)
{
e、 printStackTrace();
}
}
}

来源:

请共享您尝试过的代码。请参阅: