Question

[Solved] Error: GDK_BACKEND does not match available displays; Running Selenium using Crontab

I am trying to run selenium using cron.

import os
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from pyvirtualdisplay import Display
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True


firefox_capabilities['handleAlerts'] = True
firefox_capabilities['acceptSslCerts'] = True
firefox_capabilities['acceptInsecureCerts'] = True

binary = webdriver.firefox.firefox_binary.FirefoxBinary("/usr/bin/firefox")

now = datetime.datetime.now()
print "* Time of RUN : ",now

display = Display(visible=0, size=(1024, 768))
# display.start()
browser = webdriver.Firefox(firefox_binary=binary,executable_path=os.getcwd()+'/geckodriver')
browser.get('http://www.google.com')
print browser.title
browser.quit()

# display.stop()

Following is the error displayed in geckodriver.log

1525859641163   geckodriver INFO    geckodriver 0.20.1
1525859641167   geckodriver INFO    Listening on 127.0.0.1:34837
1525859642167   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.1xUlJhxoO4Ar"
Error: GDK_BACKEND does not match available displays

things I tried:

  1. tried running selenium without display (pyvirtualdisplay) i.e headless selenium
  2. tried binary parameter while invoking webdriver.firefox()
  3. tried geckodriver excutable(linux) in webdriver.firefox()
  4. used export Dispaly=:0; in the cron cmd
Enquirer: Prince

||

Solution #1:

  1. update latest geckodriver

  2. download latest firefox tarball and follow this step

https://tecadmin.net/install-firefox-on-linux/

3.Install the official Firefox Beta PPA

  $ sudo apt-add-repository ppa:mozillateam/firefox-next

4.Run apt-get update

 $sudo apt-get update
  1. Install firefox and xvfb (the X windows virtual framebuffer) packages

    $ sudo apt-get install firefox xvfb
    
  2. Run Xvfb in the background and specify a display number (10 in my example)

    $ Xvfb :10 -ac &
    
  3. Set the DISPLAY variable to the number you chose

    $ export DISPLAY=:10
    
  4. test the code
    #!/usr/bin/env python
    from selenium import webdriver
    browser = webdriver.Firefox()
    browser.get(‘http://iAisystem.com/‘)
    browser.quit()

firefox if you download as tar it helps to avoid download dependency files

    wget http://ftp.mozilla.org/pub/firefox/releases/61.0/linux-x86_64/en-US/firefox-61.0.tar.bz2

Note your firefox code should have headless option inorder to avoid displaying window.

Respondent: senthil sivasamy

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy