-1
當我使用它點擊下載按鈕時,會在Firefox中彈出一個下載按鈕。它正確運行並保存文件,但當我在循環中迭代它不保存,而是打開文件。下面提到的代碼的解決方案嗎?使用機器人類的Selenium webdriver中的文件下載
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);
}
火狐保存圖像:
您的問題陳述並未告訴我們您遇到的問題。請編輯正確的問題陳述以及您面臨的錯誤以進行更好的調試。 – demouser123