获取 GDK_BACKEND 与 debian 中的可用显示错误不匹配
实际上,我正在尝试通过 selenium 在远程 debian 服务器中运行无头浏览器.我在服务器中安装了 firefox 46.0.1,我使用的是 selenium 2.53.1 版本.
Actually i am trying to run a headless browser in remote debian server through selenium. I have firefox 46.0.1 installed in the server and i am using selenium 2.53.1 version.
每当我尝试运行给定的测试时,都会出现以下错误.
Whenever i tried to run a given test i got the following error.
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
Error: GDK_BACKEND does not match available displays
我在我的代码中实例化了 firefox 驱动程序,如下所示:
I have instantiated firefox driver in my code like this:
saDriver = new FirefoxDriver();
谁能帮忙?
推荐答案
我对Java不熟悉.但是在 Python 中,这个问题可以通过以下方法解决,这可能会对您有所帮助
I am not familiar with Java. However in Python this issue can be solved by the following method, this may help you
如果显示错误:GDK_BACKEND 与可用显示器不匹配,则安装 pyvirtualdisplay:
pip install pyvirtualdisplay selenium
你可能也需要 xvfb:
You might need xvfb too:
sudo apt-get install xvfb
然后尝试添加此代码:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
完整示例:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.python.org')
browser.close()
display.stop()
相关文章