You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome Driver 111无头模式下Selenide无法下载文件求助

Headless模式下Selenide文件下载超时失败问题

我有一个点击按钮下载文件的测试用例,该测试在non-headless模式下可正常通过,但在headless模式下执行时出现文件下载超时失败的情况。

版本信息

  • Selenide版本:5.25.0
  • Chrome Driver版本:111.0.5563.64

运行配置

non-headless模式

Configuration.timeout = 20000;
Configuration.fileDownload = FOLDER;

headless模式

Configuration.headless = true;
Configuration.timeout = 20000;
Configuration.fileDownload = FOLDER;

其他选项均为默认设置,如下载文件夹为build/downloads等。

下载文件代码

@SneakyThrows
public String downloadFile() {
    return downloadButton.download(10000, withExtension("pdf")).getAbsolutePath();
}

按钮元素代码

<button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedSecondary" tabindex="0" type="button" test-id="download-button">
    <span class="MuiButton-label">Download</span>
    <span class="MuiTouchRipple-root"></span>
</button>

日志对比

non-headless模式日志

13:20:09.959 INFO com.codeborne.selenide.impl.DownloadFileToFolder - Downloaded 1 files:
  #1  {root}\build\downloads\1678792759151_10256_1\109fc116-cc8b-42ba-9d7b-20733276bf64.pdf

headless模式日志

13:07:19.760 INFO com.codeborne.selenide.impl.DownloadFileToFolder - Downloaded 0 files:
13:07:19.778 INFO com.codeborne.selenide.impl.WindowsCloser - File has been opened in a new window, let's close 1 new windows
13:07:19.778 INFO com.codeborne.selenide.impl.WindowsCloser - Let's close B0C0F608D49BC5C008986B2B7AB210C5

已尝试过同类问题中的多种Chrome选项组合解决方案,但均未奏效,恳请帮助!

内容的提问来源于stack exchange,提问作者Serhii Kachan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:35:05