在Linux上运行时如何为Chrome驱动程序设置自定义TMPDIR?

时间:2019-07-23 02:55:41

标签: java selenium google-chrome selenium-chromedriver

我曾经能够通过运行以下命令使用自定义的tmp目录启动Chrome驱动程序:

driver = new ChromeDriver(new ChromeDriverService.Builder()
                    .withEnvironment(ImmutableMap.of("TMPDIR", WORK_DIR.getCanonicalPath()))
                    .build(), options);

但是我升级到了Chrome 75和chromedriver 75,但现在看来我已经做不到了。

尝试设置TMPDIR时遇到此错误:

unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

在运行时,如何防止chromedriver使用/ tmp默认目录?

1 个答案:

答案 0 :(得分:0)

请添加以下选项,并确认其是否有效。

options.addArguments("–no-sandbox");
options.addArguments("–disable-dev-shm-usage");
options.setExperimentalOption("useAutomationExtension", false);