7

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?

GAD3R
  • 4,317
  • 1
  • 23
  • 34
tempEngineer
  • 223
  • 1
  • 3
  • 13

2 Answers2

2

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()
afxentios
  • 2,502
  • 2
  • 21
  • 24
Basil Jose
  • 1,004
  • 11
  • 13
  • Getting this error when running the above sample code: `selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH` – CJ7 Jul 03 '17 at 01:47
  • selenium cannot find your gecko driver executable. Make sure it is under usr/bin folder... if you are running ubuntu and executable. – sola Aug 04 '17 at 17:52
  • It's actually working for me, Thanks. Python 3.6 + PyVirtualDisplay (0.2.1) + selenium (3.12.0) + geckodriver 0.19.1 + Mozilla Firefox 52.7.3 + CentOS + Putty – Norman Edance May 14 '18 at 03:56
0

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
sola
  • 149
  • 1
  • 2
  • 12