我正在尝试将数据从 web 表写入 excel 表并能够将数据写入 excel,但是对于 for 循环的第二个实例,它会覆盖数据或不写入数据,我的要求是将数据写入 excel 到新行中for循环的每个新实例而不是覆盖..有可能..?任何帮助将不胜感激..提前致谢
数据正在写入 excel,但在 reader.setCellData 附近需要帮助
public class DataScraper {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(40, 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++) {
}
driver.navigate().back();
driver.navigate().refresh();
}
手掌心
相关分类