【问题标题】:Selenide. download() returns FileNotFoundException: Failed to download file硒化物。 download() 返回 FileNotFoundException: 下载文件失败
【发布时间】:2018-10-31 13:05:25
【问题描述】:

我想检查使用 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 ='按钮']} 在 10000 毫秒内。截获 1 个响应。 200 "" {服务器=nginx/1.13.12, 缓存控制=私有,访问控制允许来源=*, Access-Control-Allow-Methods=POST、GET、OPTIONS、DELETE、PUT、 Connection=keep-alive,Expires=Thu,1970 年 1 月 1 日 00:00:00 GMT, 访问控制最大年龄=3600, X-Application-Context="frontend":staging:80, Content-Length=1271853, 日期=格林威治标准时间 2018 年 10 月 31 日星期三 12:41:32, Access-Control-Allow-Headers=Content-Type, x-requested-with, X-Custom-Header, 接受, 授权} application/octet-stream (1202830 字节) 在 com.codeborne.selenide.impl.DownloadFileWithProxyServer.firstDownloadedFile(DownloadFileWithProxyServer.java:94) 在 com.codeborne.selenide.impl.DownloadFileWithProxyServer.clickAndInterceptFileByProxyServer(DownloadFileWithProxyServer.java:49) 在 com.codeborne.selenide.impl.DownloadFileWithProxyServer.download(DownloadFileWithProxyServer.java:33) 在 com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:51) 在 com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:18) 在 com.codeborne.selenide.commands.Commands.execute(Commands.java:144) 在 com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99) 在 com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65) 在 com.sun.proxy.$Proxy11.download(Unknown Source)

【问题讨论】:

    标签: download selenide


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      试试这个:

          Configuration.fileDownload = FileDownloadMode.FOLDER;
      

      【讨论】:

        猜你喜欢
        • 2012-04-02
        • 1970-01-01
        • 2018-08-23
        • 1970-01-01
        • 1970-01-01
        • 2021-10-26
        • 2017-12-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多