Selenium FirefoxDriver在Headless中获取错误

问题描述 投票:1回答:2

当我尝试在无头模式下打开Firefox时,我收到以下错误:

Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port
7055; process output follows:

(process:27527): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Xlib: extension "RANDR" missing on display ":1".

(firefox:27527): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
Failed to connect to socket /tmp/dbus-VBJDTHN8W2: Connection refused
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'cpro22808', ip: '176.153.5.11', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-32-generic', java.version:
'1.7.0_55'

Driver info: driver.version: FirefoxDriver

我使用的是Ubuntu 14.04,Firefox 33,Selenium 2.44,Tomcat7,Xvfb。

我是这样开始Xvfb的:

Xvfb :1 -ac -screen 0 1024x768x24

我的java代码:

String Xport = System.getProperty("lmportal.xvfb.id", ":1");
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
webDriver = new FirefoxDriver(firefoxBinary, null);

我在这上花了几天时间,尝试了很多东西而没有解决。有人能帮我吗?

firefox ubuntu selenium selenium-webdriver xvfb
2个回答
3
投票

我也面临同样的问题。这就是我所做的,问题就消失了。

  1. 删除/var/lib/dbus/machine-id。它将在其中重新创建一个正确的。
  2. export $(dbus-launch)export NSS_USE_SHARED_DB=ENABLED。设置这些环境变量,然后重新运行。

这个问题在我的案子中消失了。


0
投票

这是一个很好的解决方案,但最后我发现了另一个选项而无需启动dbus。您可以使用-Dwebdriver.firefox.logfile=/dev/null系统属性禁用geckodriver的日志记录。

奇怪的是我可以从命令行传递它,但我必须在实例化FirefoxDriver之前显式设置它:

    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
    FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

缺点是你也丢失了任何其他日志,但我喜欢你不需要运行dbus-daemon的事实。

© www.soinside.com 2019 - 2024. All rights reserved.