【发布时间】:2020-09-16 23:32:27
【问题描述】:
我必须运行一个脚本来将特定文件下载到 Internet Explorer 中所需的文件夹,而不使用 AutoIt 和机器人。除了这个还有其他办法吗。我是自动化新手。 enter image description here enter image description here
【问题讨论】:
-
据我所知,当您单击下载链接或按钮时,WebDriver 无法访问浏览器显示的 IE 下载对话框。但是,我们可以使用名为“wget”的单独程序绕过这些对话框。更多详情,您可以查看this article。
-
这个我已经试过了。但没有运气......仍然有一些错误
-
您使用哪种语言进行 Web 驱动程序测试,Java?可以看到,如果使用 wget 方法,我们应该先获取超链接的 href 属性,然后根据 url 下载文件。您能否分享有关如何在您的网页中下载文件的相关代码。另外,我找到了一个关于使用机器人类下载文件的示例,在我这方面效果很好,您可以考虑使用这种方法吗?
-
包 Download_file.Download_file;导入 org.openqa.selenium.By;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.WebElement;导入 org.openqa.selenium.ie.InternetExplorerDriver; public class file_IE_mini { //文件已下载,但等待一段时间后未打印退出 val public static void main(String[] args) throws Exception { // TODO 自动生成的方法 stub System.setProperty("webdriver.ie.driver" , "IEDriverServer.exe"); WebDriver dr= new InternetExplorerDriver(); dr.get("demo.automationtesting.in/FileDownload.html");
-
System.out.println(dr.getTitle()); // 使用getAttribute()获取下载链接的“href”值,保存为String变量。在这种情况下,我们将变量命名为“sourceLocation”。 WebElement downloadButton = dr.findElement(By.xpath("//a[@class='btn btn-primary']")); String sourceLocation = downloadButton.getAttribute("href");
标签: java selenium selenium-webdriver internet-explorer automation