【问题标题】:Is it required to set the DISPLAY for headless firefox browser on linux machinelinux机器上的headless firefox浏览器是否需要设置DISPLAY
【发布时间】:2019-02-23 09:23:48
【问题描述】:

我想运行无头浏览器,下面是相同的代码。 但是,当我运行它时。它显示“错误:未指定 DISPLAY 环境变量”

try {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.driver", "INFO");
profile.setPreference("webdriver.log.file", targetDir + File.separator + "firefoxSeleniumServer.log");
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv;text/plain");
if(platform.equalsIgnoreCase("linux")) {
DesiredCapabilities desiredCap = DesiredCapabilities.firefox();
profile.setPreference("browser.download.dir",System.getProperty("user.dir")+ File.separator + "target");
System.setProperty("webdriver.gecko.driver", "/test/geckodriver/geckodriver");
System.setProperty("webdriver.firefox.bin","/usr/bin/firefox/firefox");
desiredCap.setCapability("headless", true);
driver = new FirefoxDriver();
}

但是,当我设置显示时,它显示无法在 DISPLAY:99 上打开 firefox

我也尝试设置 xvfb。但这也没有用。

由于我在这里使用 gekco 驱动程序,我是否需要进行更多配置。

【问题讨论】:

  • 您完成了创建配置文件和功能的所有工作,但是您在不使用它们的情况下实例化了 FirefoxDriver()!

标签: java selenium-webdriver geckodriver xvfb firefox-headless


【解决方案1】:

我认为您应该将DesiredCapabilities 对象作为参数提供给FirefoxDriver 构造函数:

参考文献

【讨论】:

  • 不推荐使用上面的 selenium3。我也尝试过关注,但仍然面临同样的问题。 binary = new FirefoxBinary(new File("/bin/firefox/firefox")); options.setBinary(binary); driver = new FirefoxDriver(options);
  • 但是您是否尝试过使用已弃用的类?
猜你喜欢
  • 2021-07-27
  • 2019-11-09
  • 2018-06-08
  • 2011-10-08
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2018-06-03
  • 2016-05-19
相关资源
最近更新 更多