首页 > 解决方案 > 硒化物。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。

标签: downloadselenide

解决方案


由于你的项目设置,你应该使用 try catch,使用这个:

        try {
        $("selector").download();
    }catch(FileNotFoundException e){}

推荐阅读