Getting GDK_BACKEND does not match available displays error in debian

hellWarrior picture hellWarrior · Nov 24, 2016 · Viewed 15.5k times · Source

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?

Answer

Basil Jose picture Basil Jose · Jan 26, 2017

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