When I Clicked download button using it opens a download pop up in firefox. Its running correctly and saving the files but when i iterate in loop its not saving instead its opening the file.Any solution for below mentioned code it ?
for (int j = 0; j < StoreSelectedYear_size; j++) {
System.out.println(StoreSelectedYear.get(j));
YearSelection(StoreSelectedYear.get(j));
Thread.sleep(5000);
filedownload(i);
}
StoreSelectedYear.clear();
}
}
public void YearSelection(String StoreSelectedYearStr) throws InterruptedException, AWTException {
Select yearselction = new Select(driver.findElement(By.cssSelector("#u14_input")));
yearselction.selectByVisibleText(StoreSelectedYearStr);
Thread.sleep(5000);
}
public void filedownload(int i) throws AWTException, InterruptedException {
driver.findElement(By.xpath("//button[@id='export']")).click();
Thread.sleep(6000);
Robot robot = new Robot();
robot.delay(5000);
// Thread.sleep throws InterruptedException
if (i == 0) {
robot.keyPress(KeyEvent.VK_DOWN);
robot.delay(2000);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
}
Firefox save image: