Getting GDK_BACKEND does not match available displays error in debian

♀尐吖头ヾ 提交于 2019-12-10 14:23:38

问题


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

I have instantiated firefox driver in my code like this:

saDriver = new FirefoxDriver();

can anyone help?


回答1:


I am not familiar with Java. However in Python this issue can be solved by the following method, this may help you

If it says Error: GDK_BACKEND does not match available displays then install pyvirtualdisplay:

pip install pyvirtualdisplay selenium

You might need xvfb too:

sudo apt-get install xvfb

Then try adding this code:

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()

Full example:

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()



回答2:


You need to export the display in the shell that selenium server is running in otherwise it will not be able to open the browser.

nohup sudo Xvfb: 10 - ac &
export DISPLAY=10


来源:https://stackoverflow.com/questions/40789338/getting-gdk-backend-does-not-match-available-displays-error-in-debian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!