Selenide. download() 返回 FileNotFoundException: 下载文件失败

4

我想要使用Selenide download()方法来检查文件下载,但是在文件已经下载完成的情况下还捕获到FileNotFoundException和'Intercepted 1 responses'错误。

我有一个按钮,点击该按钮会下载一个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: 无法在10000毫秒内下载文件 {By.xpath: //div[@class='task-list_container_scroll-view']/div[1]/div[@class='ng-star-inserted'][1]//common-task-view//span[@role='button']} 。截获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-alive, Expires=Thu, 01 Jan 1970 00:00:00 GMT, Access-Control-Max-Age=3600, X-Application-Context="frontend":staging:80, Content-Length=1271853, Date=Wed, 31 Oct 2018 12:41:32 GMT, Access-Control-Allow-Headers=Content-Type, x-requested-with, X-Custom-Header, accept, authorization} application/octet-stream (1202830字节) at com.codeborne.selenide.impl.DownloadFileWithProxyServer.firstDownloadedFile(DownloadFileWithProxyServer.java:94) at com.codeborne.selenide.impl.DownloadFileWithProxyServer.clickAndInterceptFileByProxyServer(DownloadFileWithProxyServer.java:49) at com.codeborne.selenide.impl.DownloadFileWithProxyServer.download(DownloadFileWithProxyServer.java:33) at com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:51) at com.codeborne.selenide.commands.DownloadFile.execute(DownloadFile.java:18) at com.codeborne.selenide.commands.Commands.execute(Commands.java:144) at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:99) at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65) at com.sun.proxy.$Proxy11.download(Unknown Source)
2个回答

1

由于您的项目设置,建议使用try catch,请使用以下代码:

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

1

试试这个:

    Configuration.fileDownload = FileDownloadMode.FOLDER;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接