简体   繁体   English

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

[英]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.

相关问题 如何使用 Selenium webdriver 和 Java 为 firefox 设置代理? - How do I set a proxy for firefox using Selenium webdriver with Java? 如何使用 java Selenium WebDriver 下载文件? - How do I download a file using java Selenium WebDriver? 如何使用Selenium Webdriver取消在Firefox中的下载? - How can i cancel a download in firefox by using Selenium Webdriver? 如何使用带有Java的Selenium Webdriver处理允许弹出的Firefox插件 - How do I handle allow pop-up of plug-in for firefox using Selenium Webdriver with Java 我如何处理下载 firefox 对话框(接受下载并取消它)+ selenium java - How can i handle download firefox dialogbox (accept download and cancel it ) + selenium java Java-Selenium WebDriver-如何检查“文件下载”对话框是否可见? (不下载仅能见度) - Java - Selenium WebDriver - How do I check if the File Download Dialog Box is visible? (Not download Only visibility) 如何使用带有Java的Selenium WebDriver在iframe中拖动对象 - How do I drag an object in an iframe using Selenium WebDriver with Java 如何使用java在selenium webdriver中提示输入并使用结果? - How can I prompt for Input in selenium webdriver using java and use the result? 如何使用 Java 设置 Selenium WebDriver? - How do I setup Selenium WebDriver with Java? 如何在Selenium Webdriver中执行javascript提示并等待接受输入 - how to execute javascript prompt in selenium webdriver and wait for accept input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM