首页 > 解决方案 > 在 Jenkins 中,sendKeys(filePath) 间歇性地给 selenium InvalidArgumentException of fileNotFound 尽管文件存在

问题描述

在 selenium + Java 中,我使用 webElement.sendKeys(filePath) 将文件上传到 jenkins 的网页中,这会导致间歇性 InvalidArgumentException 异常,尽管文件在那里。文件位于资源文件夹中的源代码仓库中;

org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : 
/blah/blah1/abc.pdf
 (Session info: headless chrome=88.0.4324.96)

    if (driver instanceof RemoteWebDriver) {
        ((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
    }
    assertThat(file.exists()).isTrue();
    webElement.sendKeys(file.getAbsolutePath());

尽管断言总是通过,但这里 sendKeys 间歇性地给出 InvalidArgumentException。

有人遇到过类似的问题吗?请提供任何解决方案。关于 linux docker 容器的详细信息

os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-1103-azure', java.version: 
'11.0.5'
chrome: {chromedriverVersion: 91.0.4472.19 
selenium.version :- 3.141.59

标签: javaseleniumselenium-webdriverselenium-chromedrivercucumber-jvm

解决方案


推荐阅读