繁体   English   中英

如何在JAVA中使用Selenium在firefox Webdriver上接受下载提示?

[英]How do I accept the download prompt on the firefox webdriver using selenium in JAVA?

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

您可以尝试使用以下代码来下载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; 

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

您为什么不选择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是一个简单的解决方案,您可以使用它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM