[英]How do I accept the download prompt on the firefox webdriver using selenium in JAVA?
I am testing a page I am building and I was hoping to find out if it is possible to accept the download prompt using selenium? 我正在测试正在构建的页面,希望能找到是否可以使用硒接受下载提示? I am using the Firefox Webdriver. 我正在使用Firefox Webdriver。
You can try using the following code, for downloading a zip file: 您可以尝试使用以下代码来下载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;
The easiest way to do this is to set have your test use a firefox profile that is setup to automatically accept the download prompt. 最简单的方法是设置您的测试使用设置为自动接受下载提示的firefox配置文件。 See here for help creating a new profile. 请参阅此处以获取创建新配置文件的帮助。 To use this profile in your test see the top answer to the question here . 要在测试中使用此配置文件,请在此处查看问题的最高答案。 However I also recommend reading this , which will explain why you don't actually need to download the files to test that your download functionality is working. 但是,我还建议您阅读this ,这将解释为什么您实际上不需要下载文件来测试您的下载功能是否正常工作。
Why don't you choose Sikuli, it is too simple. 您为什么不选择Sikuli,这太简单了。
Add sikuli-java.jar file in build path, install Picpick soft, save images of save file, ok button using Picpick. 在构建路径中添加sikuli-java.jar文件,安装Picpick soft,使用Picpick保存保存文件的图像,单击确定按钮。
Type the following commands 输入以下命令
new Screen().click(new Pattern("E:\\simage\\save.png")); //here e:\\..is image file path
new Screen().click(new Pattern("E:\\simage\\ok.png"));
It's over. 结束了。
是的,sikuli是一个简单的解决方案,您可以使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.