当前位置: 首页 > 知识库问答 >
问题:

硒与Xvfb:火狐。NotConnectedException

窦志新
2023-03-14

我在服务器上运行硒,我希望它在客户端上显示浏览器。我已经在我的服务器上启动了xvfb,如下所示:

Xvfb :1 -screen 0 1024x768x24 &

然后在我的Java代码上我写道:

    String xPort = System.getProperty("Importal.xvfb.id", ":1");
    FirefoxBinary firefoxBinary = new FirefoxBinary(new File("/usr/lib/firefox/firefox"));
    firefoxBinary.setEnvironmentProperty("DISPLAY", xPort);
    WebDriver webDriver = new FirefoxDriver(firefoxBinary, null);

但当我启动时,我有一个例外:

javax.servlet.ServletException: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/lib/firefox/firefox) on port 7055; process output follows: 

(process:28971): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Xlib:  extension "RANDR" missing on display ":1".
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default

Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'franceservice', ip: '149.202.55.131', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-22-generic', java.version: '1.8.0_45'
Driver info: driver.version: FirefoxDriver
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:397)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/lib/firefox/firefox) on port 7055; process output follows: 

(process:28971): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Xlib:  extension "RANDR" missing on display ":1".
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default

Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'franceservice', ip: '149.202.55.131', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-22-generic', java.version: '1.8.0_45'
Driver info: driver.version: FirefoxDriver
    org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:134)
    org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:276)
    org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:221)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:212)
    com.franceservice.controllers.bo.BOResultat.sendById(BOResultat.java:329)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:172)
    org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:384)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:342)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
    org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:303)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:316)
    org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:286)
    org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1073)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:377)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:

(process:28971): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
Xlib:  extension "RANDR" missing on display ":1".
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default

    org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
    org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:276)
    org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:116)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:221)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
    org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:212)
    com.franceservice.controllers.bo.BOResultat.sendById(BOResultat.java:329)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:172)
    org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:384)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:342)
    org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
    org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:303)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:316)
    org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:286)
    org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1073)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:377)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Selenium的版本是2.47.1,firefox的版本是33.0。

共有1个答案

方浩旷
2023-03-14

你需要RANDR分机。尝试以下方法:

Xvfb :1 -screen 0 1024x768x24 -extension RANDR &
 类似资料:
  • 根据< code>window_handles文档: 窗口句柄(_H) 返回当前会话中所有窗口的句柄。 但是,在打开一个新选项卡后,我无法在列表中看到新句柄: 如您所见,具有相同的值,但我看到浏览器中打开了 2 个选项卡。是我做错了什么吗?如果是,我应该如何获取新选项卡的句柄? 使用: 硒 2.44.0 (最新) 火狐 35.0 (最新) 蟒蛇 2.7.6 请注意,如果我在Chrome中做类似的事

  • 我在尝试启动浏览器时收到此错误消息: org.openqa.selenium.firefox.NotConnected异常:45000 ms后无法连接到端口7055上的主机127.0.0.1。Firefox控制台输出: s":[],"hasEmbeddedWebExtense": false} 我使用的是和。

  • 我在selenium firefox webdriver上运行了Cumber JVM测试。在eclipse上运行测试时一切都很正常,但当它们在Jenkins上运行时,浏览器上的url设置正确,但页面永远不会加载。Jenkins安装在windows机器上(不是无头)。可能很简单,但我似乎在网上找不到任何能给我指明正确方向的东西。 这篇文章(詹金斯与Xvfb和硒 - 火狐开始但什么都没有执行)指向硒更

  • 火狐中国版是谋智专为中国用户定制的浏览器,提供出色的全方位浏览体验。 立体:“火狐魔镜”让您边看视频听音乐,边轻松浏览网页;更整合众多本土内容 安全:独有架构对病毒木马有更强的抵抗力;首创浏览器植入防恶意软件功能 强大:5000个扩展帮您实现成千上万个新功能,更可随心所欲定制 智能:只需要在地址栏中输入一个字母或汉字,就知道您需要什么

  • 我有一个超级简单的测试脚本(如下)来开始使用WebDriver。当我运行测试(C#-Visual Studio 2015)时,它会打开一个Firefox浏览器,然后什么也不做。 有几个帖子讨论了以下问题,我也得到了: OpenQA. Selenium.在45000毫秒内启动套接字失败。试图连接到以下地址:127.0.0.1:7055。 但是那些关于这个问题的帖子很旧了,也有一个主要的不同——他们的

  • 我试图找到解决这个问题的方法,我花了很多时间,但这对我来说几乎是不可能的。 问题:我在Firefox中使用Selenium和Java。我需要找到一个元素(列表框)并点击它。因此,代码找到元素,但单击操作不起作用。它在Google Chrome中每次都能很好地工作,只是有时在Firefox中(使用相同的Java代码有时工作,有时不工作)。 当程序进入页面时,有一部分代码包含元素: 还有一部分代码在单