gpt4 book ai didi

java - 如何使用selenium匹配网页中excel中的字符串?

转载 作者:行者123 更新时间:2023-12-01 16:42:49 24 4
gpt4 key购买 nike

我正在尝试从 Excel 工作表中获取字符串,并想检查该字符串是否存在于网页中。这是我正在尝试的代码,

public static void main(String[] args) throws IOException {

System.setProperty("webdriver.chrome.driver", "driver path");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
driver.get(url);

String ps = driver.getPageSource();
File src = new File("excel path\\Data.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet Sheet1 = wb.getSheetAt(0);
XSSFRow row = Sheet1.getRow(0);

for(int i=0;i<row.getLastCellNum();i++) {
if(ps.contains()) {

System.out.println("TEXT is present");
}
else {
System.out.println("TEXT is not present");
}
}

}

}

但是它不起作用,任何人都可以帮助我吗...

最佳答案

在 if 条件之前尝试这个。

String strtext=row.getcell(i).getStringCellValue()
Your modified code looks like:
for(int i=0;i<row.getLastCellNum();i++) {
String strtext=row.getcell(i).getStringCellValue();//ensure your cell type is text.
//then your if condition
if(ps.contains(strtext)){

关于java - 如何使用selenium匹配网页中excel中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61830570/

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