尽管我正在控制台上获得输出。
public class DataScraper {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://etrain.info/in?PAGE=LIST--RAJ-TRAINS--1");
// *[@id="lowerdata"]/table/tbody/tr[1]/td/table/tbody/tr[5]/td[1]/a
// *[@id="lowerdata"]/table/tbody/tr[1]/td/table/tbody/tr[6]/td[1]/a
// *[@id="lowerdata"]/table/tbody/tr[1]/td/table/tbody/tr[29]/td[1]/a
String beforeXpath_TrainNoRow = "//td[@id='content']//tr[";
String afterXpath_TrainNoRow = "]//td[1]";
// div[@id='sublowerdata']//tr[3]//td[1]
// div[@id='sublowerdata']//tr[11]//td[1]
String beforeXpath_No = "//div[@id='sublowerdata']//tr[";
String afterXpath_No = "]//td[1]";
// int rowCount = TrainList.size();
Xls_Reader reader = new Xls_Reader(
"C:\\Selenium_Automation\\Projects\\DataDriven_FW\\src\\com\\testdata\\TrainSchedule.xlsx");
if (!reader.isSheetExist("Rajdhani")) {
reader.addSheet("Rajdhani");
reader.addColumn("Rajdhani", "IslNo");
// reader.addColumn("TrainSearch", "TrainName");
}
for (int i = 5; i <= 30; i++) {
String actualXpath_TrainNoRow = beforeXpath_TrainNoRow + i + afterXpath_TrainNoRow;
WebElement TrainNo = driver.findElement(By.xpath(actualXpath_TrainNoRow));
TrainNo.click();
Thread.sleep(5000);
List<WebElement> rows = driver.findElements(By.xpath("//table[@id='schtbl']//tr"));
System.out.println("total rows is " + rows.size());
int rowCount = rows.size();
for (int j = 3; j <= rowCount - 1; j++) {
String actualXpath_No = beforeXpath_No + j + afterXpath_No;
String SrNo = driver.findElement(By.xpath(actualXpath_No)).getText();
int islNo = Integer.parseInt(SrNo);
System.out.println(islNo);
reader.setCellData("Rajdhani", "IslNo", j, SrNo);
}
driver.navigate().back();
driver.navigate().refresh();
// table[@id='schtbl']//tr -- table rows inner
}
}
}
预期输出应为每行1到9,并追加下一个实例输出,即1 2..9 1 2..9对接我对于第一个实例仅获得1到9。