download - 硒化物。download() 返回 FileNotFoundException: 下载文件失败
问题描述
我想检查使用 Selenide download() 方法下载文件,但捕获 FileNotFoundException 和错误“拦截 1 响应”,尽管文件已下载。
我有按钮,单击它会导致下载 zip 文件。元素没有 href 属性。
我使用 Selenide 5.0.0,chromdriver.exe 2.43
我有以下设置
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
以下代码调用错误
public static SelenideElement actionButton() {return $(By.xpath("//div[@class='task-list_container_scroll-view']/div[1]/div[@class='ng-star-inserted'][1]//common-task-view//span[@role='button']"));}
File file = actionButton().download(10000);
java.io.FileNotFoundException: 无法下载文件 {By.xpath: //div[@class='task-list_container_scroll-view']/div[1]/div[@class='ng-star-inserted'][ 1]//common-task-view//span[@role='button']} 在 10000 毫秒内。截获 1 个响应。200 "" {Server=nginx/1.13.12, Cache-Control=private, Access-Control-Allow-Origin=*, Access-Control-Allow-Methods=POST, GET, OPTIONS, DELETE, PUT, Connection=keep-活着,Expires=Thu,1970 年 1 月 1 日 00:00:00 GMT,Access-Control-Max-Age=3600,X-Application-Context="frontend":staging:80,Content-Length=1271853,Date=Wed, 2018 年 10 月 31 日 12:41:32 GMT,Access-Control-Allow-Headers=Content-Type,x-requested-with,X-Custom-Header,accept,authorization} application/octet-stream(1202830 字节)在 com。 codeborne.selenide.impl.DownloadFileWithProxyServer。
解决方案
由于你的项目设置,你应该使用 try catch,使用这个:
try {
$("selector").download();
}catch(FileNotFoundException e){}
推荐阅读
- javascript - 我想正确返回儿童物品。我怎样才能?
- r - 在 dbplyr 中传递要作为函数参数应用的函数
- node.js - 14天后Node js Cron Job执行
- javascript - 打开(默认)相机应用程序*不*上传文件
- jpa - java.util.ArrayList 不能转换为类 [Ljava.lang.Object;
- javascript - node Fetch 从 API 返回未定义的主体
- typo3 - Realurl 配置不正确
- azure-devops - 如何从 yaml 管道将对象传递给用于 ARM 部署的 overrideParameters
- node.js - express.js中猫鼬中的时刻日期相关查询(得到零结果)
- wpf - 使用 INotifyDataErrorInfo 添加错误信息时下移项目