我想从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");
}
}
}
}
但它不工作,任何一个人可以帮助我在这个pls ...
在你的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)){