下载文件存储位置和处理使用selenium webdriver与JAVA下载Popup [英] download file stored Location and handling Download Popup using selenium webdriver with JAVA

查看:461
本文介绍了下载文件存储位置和处理使用selenium webdriver与JAVA下载Popup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请使用以下几点实现建议一个想法。

Please suggest an idea with following points implementations

1.如何使用带有JAVA的Selenium Webdriver处理IE中的下载弹出窗口?

1.how to handle the Download popup in IE with Selenium Webdriver with JAVA?

2.如何通过使用JAVA将xml文件存储在不同的位置?

2.how to store that xml file in different location by using JAVA?

注意:我们将传递n个输入,每个输入都有一个xml文件,需要所有的xml文件下载并保存在不同的位置

Note: we will pass 'n' number of Inputs and each input have an xml file , required all the xml file download and save in different location

推荐答案

我建议您不要使用selenium自动执行文件下载。这是你不想跌倒的陷阱。文件下载在不同浏览器中的工作方式不同。人们会推荐使用AutoIT,但它仅适用于Windows,因此跨平台测试是不可能的。由于您使用Java绑定,您可以使用Robot类将鼠标指针移动到窗口上的某个位置,并发送本地点击。根据我的经验,这个解决方案真的很片面。您不知道您必须点击的确切位置,并且您正在盲目点击事件的Robot。为了增加这一点,当您使用硒网格在远程机器上运行测试时,事情变得更加困难。

I would recommend you NOT to automate file download using selenium. It's a trap you don't want to fall for. File download works differently in different browsers. People will recommend using AutoIT, but it only works for windows, so cross platform testing is not possible. Since you use Java bindings, you could use the Robot class, to move your mouse pointer to a certain location on the window and send a native click. In my experience this solution is really flaky. You don't know the exact location where you must click and with Robot you are blindly clicking on things. To add to this, when you are running tests on remote machine using selenium grid, things get even more difficult.

那么如何下载文件?只需获得底层链接即可下载DOM中可用的文件,并触发GET请求。如果要验证文件,请下载内容。如果您不想验证内容,只需回复代码即可。 这里是一个非常棒的博客,Java示例如何在后台使用http请求下载文件,并详细说明为什么使用selenium下载文件是一个坏主意。

So how do you download the file? Just get the underlying link to download the file available in your DOM and fire a GET request. Download the content if you want to validate the file. If you don't want to validate the content, just response code is fine. Here is a fantastic blog with Java examples on how to download files in the background using http requests and detailed explanation on why downloading files using selenium is a bad idea.

这篇关于下载文件存储位置和处理使用selenium webdriver与JAVA下载Popup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆