如何在JAVA中使用selenium接受firefox webdriver上的下载提示?

我正在测试我正在构建的页面,我希望找出是否可以使用selenium接受下载提示? 我正在使用Firefox Webdriver。

最简单的方法是设置让测试使用firefox配置文件,该配置文件设置为自动接受下载提示。 请参阅此处获取有关创建新配置文件的帮 要在测试中使用此配置文件,请在此处查看问题的最佳答案。 但是我也建议阅读这个 ,这将解释为什么你实际上不需要下载文件来测试你的下载function是否正常工作。

您可以尝试使用以下代码下载zip文件:

FirefoxProfile profile = new FirefoxProfile(); //MIME type for zip file "application/zip" profile.setPreference("browser,helperapps.neverAsk.SaveToDisk", "application/zip"); // 0 = desktop, 1 = default download folder , 2 = user defined location. profile.setPreference("browser.download.folderList",0); driver = new FirefoxDriver(profile); baseUrl = " http://www.yourwebsite.com "; driver.get(baseUrl); driver.findElement(By.id("downloadFile")).click; 

你为什么不选择Sikuli,这太简单了。
在构建路径中添加sikuli-java.jar文件,安装Picpick soft,保存保存文件的图像,使用Picpick保存按钮。
键入以下命令

 new Screen().click(new Pattern("E:\\simage\\save.png")); //here e:\\..is image file path new Screen().click(new Pattern("E:\\simage\\ok.png")); 

结束了。

是sikuli是你可以使用它的简单解决方案