gpt4 book ai didi

java - 从 Excel 中复制文本并将其粘贴到文本框中,然后单击“搜索”后的链接

转载 作者:行者123 更新时间:2023-12-01 12:03:45 26 4
gpt4 key购买 nike

我现在一直在与 Selenium 和 Sikuli 作斗争。目前,我陷入了困境,必须从 Excel 中获取值并在文本框中搜索它(文本框位于网页上,该网页是一个安全站点,即 html 元素被嵌入并且在页面源代码中不可见)。搜索后,我将获得结果,如果出现结果,我将必须单击链接,否则退出并从 Excel 中搜索下一个值。

谁能帮我解决一下吗?提前致谢

最佳答案

您可以使用Apache POI要从 Excel 读取单元格值,请尝试以下操作:

首先,如果您使用 maven,请将其添加到您的 pom.xml 中:

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>

然后使用此代码从 Excel 文件中获取字符串值:

public static String ReadExcel (String filename) throws InvalidFormatException {

File excel = null;
FileInputStream file = null;

try {

excel = new File("D:\\tmp\\" + filename + ".xls");
file = new FileInputStream(excel);

Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();

while (rowIterator.hasNext()) {

Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();

while (cellIterator.hasNext()) {

cell = cellIterator.next();

if (!cell.getStringCellValue().isEmpty()) {


if (cell.getCellType() == Cell.CELL_TYPE_STRING) {

// your method to find data on page with param cell.getStringCellValue()
}
}
}
}

} catch (IOException ioe) {
ioe.printStackTrace();
} finally {

if (file != null && excel != null) {

file.close();
//excel.delete();
}
}

return null;
}

然后在每个单元格迭代中调用搜索方法,该方法会将值与页面上所需的值进行比较。

希望这会对您有所帮助。

关于java - 从 Excel 中复制文本并将其粘贴到文本框中,然后单击“搜索”后的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27819421/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com