52413

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:

<ol> <li>tried running selenium without display (pyvirtualdisplay) i.e headless selenium</li> <li>tried binary parameter while invoking webdriver.firefox() </li> <li>tried geckodriver excutable(linux) in webdriver.firefox() </li> <li>used export Dispaly=:0; in the cron cmd</li> </ol>

Answer1:

<ol> <li>

update latest geckodriver

</li> <li>

download latest firefox tarball and follow this step

</li> </ol>

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 <ol start="5"> <li>

Install firefox and xvfb (the X windows virtual framebuffer) packages

$ sudo apt-get install firefox xvfb </li> <li>

Run Xvfb in the background and specify a display number (10 in my example)

$ Xvfb :10 -ac & </li> <li>

Set the DISPLAY variable to the number you chose

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

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.

Recommend

  • Aspect ratio behaviour of - internal dimensions and element size
  • Cross-origin request blocked, origin 'null' no access
  • Is there a way to act before the scroll event?
  • chrome PDF viewer can't download file
  • How to clear Firefox' console via javascript?
  • Slow performance in hybrid AngularJS and Angular application in Safari
  • Change the font color of disabled input text box?
  • How to get the click event on sIFR embedded tag in IE?
  • Understanding Intl.DateTimeFormat as a JavaScript object
  • how to display   in Mozilla using XSL.
  • pygame.init() shows as undefined variable after installing Pygame
  • cd command not working with execvp
  • You tube videos are not playing
  • Is there a way to set up a fallback for the formAction attribute in HTML5?
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • JSON encode and decode on PHP
  • Building Qt project for C++11 standard
  • How can I tell a form not to dispose a particular control when it closes?
  • SonarQube: Cannot deactivate rule with missing quality profile
  • wxPython: displaying multiple widgets in same frame
  • App restarts from wrong activity
  • AJAX Html Editor Extender upload image appearing blank
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Seeking advice on Jetty HttpClient Hang
  • How to rebase a series of branches?
  • Display issues when we change from one jquery mobile page to another in firefox
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Optimizing database types to compact database (SQLite)
  • Window Size for Mac application
  • Cross-Platform Protobuf Serialization
  • Trying to switch camera back to front but getting exception
  • Do I've to free mysql result after storing it?
  • Google cloud sdk not working when python points python3
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • using HTMLImports.whenReady not working in chrome
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Turn off referential integrity in Derby? is it possible?
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Android Heatmap on canvas or ImageView