日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java selenium 获取表格数据_Selenium Webdriver如何通过获取Excel输入从表中选择记录...

發布時間:2025/3/19 java 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java selenium 获取表格数据_Selenium Webdriver如何通过获取Excel输入从表中选择记录... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

據我所知,您正在嘗試從遠程位置讀取文件,然后從中讀取信息 . 如果您可以使用Apache POI庫在運行時讀取內容,那將是一個很好的做法 .

在我的項目中,我使用Apache POI庫讀取Excel工作表中的所有內容,以設置變量的值 . 這是我如何實現它的代碼片段 . 希望這將指導您找到合適的解決方案 . :)

public void readExcelDoc() throws FileNotFoundException, IOException

{

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("excelDoc//scripts.xls"));

HSSFWorkbook wb = new HSSFWorkbook(fs);

HSSFSheet sheet = wb.getSheetAt(0);

HSSFRow row = null;

HSSFCell cell = null;

int rows = 0; // No of rows

// rows = sheet.getPhysicalNumberOfRows();

rows = sheet.getLastRowNum();

int cols = 2; // No of columns

int tmp = 0;

// This trick ensures that we get the data properly even if it doesn't start from first few rows

for(int i = 0; i < 10 || i < rows; i++) {

row = sheet.getRow(i);

if(row != null) {

tmp = sheet.getRow(i).getPhysicalNumberOfCells();

if(tmp > cols) cols = tmp;

}

}

int testRowNo = 0;

String rowName = "Test Name";

String columnValue = " ";

//Iterate through Row and columns here. Excluding 1st row for title names

for(int r = 1; r <= rows; r++) {

row = sheet.getRow(r);

if(row != null) {

//Browse through columns using c

for(int c = 0; c < cols; c++) {

if(c==0) //Only taking data from Cell 0; Ignoring any other inputs

{

cell = row.getCell((short)c);

try

{

if(cell.getStringCellValue().contains(rowName))

{

testRowNo =row.getRowNum();

}

if(testRowNo > 0 )

{

if(cell.getColumnIndex() == 0 && row.getRowNum() > testRowNo && cell.getStringCellValue().length() !=0)

{

try{

String cellValue = cell.getStringCellValue().toLowerCase();

//System.out.println(cellValue);

scriptType.add(cellValue);

}

catch(IllegalStateException e)

{

e.printStackTrace();

scriptType.add(cell.getStringCellValue());

}

}

}

}

catch(NullPointerException e)

{

}

}

if(c==1)

{

cell = row.getCell((short)c); //this sets the column number

if(testRowNo == 0)

{

try{

String cellValue = cell.getStringCellValue();

//System.out.println(cellValue);

columnValue = cellValue;

}

catch(IllegalStateException e)

{

String cellValue = cell.toString();

columnValue = cellValue;

}

catch(NullPointerException e)

{

String cellValue = nodata;

columnValue = cellValue;

}

}

}

if(c==2)

{

cell = row.getCell((short)c); //this sets the column number

if(testRowNo == 0)

{

try{

String cellValue = cell.getStringCellValue();

//System.out.println(cellValue);

inputParameters.put(cellValue, columnValue);

}

catch(IllegalStateException e)

{

String cellValue = cell.toString();

inputParameters.put(cellValue, columnValue);

}

catch(NullPointerException e)

{

String cellValue = nodata;

inputParameters.put(cellValue, columnValue);

}

}

}

}

}

}

System.out.println("---------The parameters set from excel are : ---------");

@SuppressWarnings("rawtypes")

Iterator iterator = inputParameters.keySet().iterator();

while (iterator.hasNext()) {

String key = iterator.next().toString();

String value = inputParameters.get(key).toString();

System.out.println(key + " : " + value);

}

}

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Java selenium 获取表格数据_Selenium Webdriver如何通过获取Excel输入从表中选择记录...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。