【发布时间】:2018-05-23 09:43:57
【问题描述】:
我尝试使用 Selenium WebDriver 和 Robot 类在 IE11 中下载文件,我正在使用 IntelliJ 并使用 IE11 在 Selenium Grid 上运行测试。
我不使用 element.click() 函数,因为控件停在那里,因此我使用 sendKeys 专注于下载按钮。出现下载弹窗,Robot 类来了。我尝试在 Robot 的帮助下按 Alt+S 保存文件,但它没有在 IE 上按 Alt+S,而是在我的 IntelliJ 上按 Alt+S !!!。这是我的代码:
if (webBrowser.equalsIgnoreCase("ie")) {
WebElement downloadReport = webDriver.findElement(By.id("clientReportDownload"));
try {
Robot robot = new Robot();
// sendKeys to focus on Download button and press Enter to download
downloadReport.sendKeys("");
downloadReport.sendKeys(Keys.ENTER);
waitSeconds(2);
// wait for Download popup
robot.setAutoDelay(250);
// simulate presse Alt + S to save file -> It presses Alt+S on IntelliJ instead !!!
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_S);
waitSeconds(2);
} catch (AWTException e) {
e.printStackTrace();
}
}
有人对此有解决方案吗?
【问题讨论】:
标签: java selenium selenium-webdriver automated-tests awtrobot