Selenium Firefox webdriver works with images created from Ubuntu, but not images created on Debian

This is a rather strange situation that I encountered. I have the following simple Python script:

from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.add_argument("-headless") browser = webdriver.Firefox(firefox_options=options) browser.get("https://www.google.com") print(browser.current_url) 

And a wrapper for the script:

 #!/bin/bash wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz tar -xzvf geckodriver-v0.19.1-linux64.tar.gz chmod 777 geckodriver mv geckodriver /usr/bin/ firefox -v # python3 when ubuntu python test.py 

In addition, I have two Dockerfiles:

Dockerfile A (Ubuntu; works great):

 FROM ubuntu:16.04 RUN apt-get update -y && apt-get install -y python3 \ python3-pip \ firefox \ build-essential \ wget COPY . /app WORKDIR /app RUN pip3 install --upgrade pip RUN pip3 install -r requirements.txt ENTRYPOINT ["bash"] CMD ["test_wrapper.sh"] 

Dockerfile B (Debian; crashes):

 FROM continuumio/anaconda3:5.0.1 RUN apt-get update -y && apt-get install -y iceweasel \ build-essential \ wget COPY . /app WORKDIR /app RUN pip install --upgrade pip RUN pip install -r requirements.txt ENTRYPOINT ["bash"] CMD ["test_wrapper.sh"] 

test.py run from an image created from Dockerfile B throws the following exception:

selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1

geckodriver.log shows the following error:

GTK_BACKEND doesn't match available displays

Has anyone come across this and knew a workaround? It should not need access to the display, because it works without a brain - unless selenium Firefox's parameters are different in iceweasel than regular Firefox? I expected similar behavior and I would rather use an Anaconda image

I just tried this one , which I would almost certainly allow, but it didn’t work.

EDIT . I don't think this is a geckodriver problem, as I tried to use the same Docker file with firefox-esr instead of iceweasel . Also, I tried to run the container interactively and firefox -headless (which on ubuntu starts a firefox headless session), it gave the exact same GTK serial message.

+5
source share
2 answers
 RUN apt-get install -y --no-install-recommends apt-utils RUN apt-get install -y wget \ build-essential \ libgl1-mesa-glx \ libgtk-3-dev ARG FIREFOX_VERSION=58.0.2 RUN wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/en-US/firefox-$FIREFOX_VERSION.tar.bz2 \ && rm -rf /opt/firefox \ && tar -C /opt -xjf /tmp/firefox.tar.bz2 \ && rm /tmp/firefox.tar.bz2 \ && mv /opt/firefox /opt/firefox-$FIREFOX_VERSION \ && ln -fs /opt/firefox-$FIREFOX_VERSION/firefox /usr/bin/firefox ARG GK_VERSION=v0.19.1 RUN wget --no-verbose -O /tmp/geckodriver.tar.gz http://github.com/mozilla/geckodriver/releases/download/$GK_VERSION/geckodriver-$GK_VERSION-linux64.tar.gz \ && rm -rf /opt/geckodriver \ && tar -C /opt -zxf /tmp/geckodriver.tar.gz \ && rm /tmp/geckodriver.tar.gz \ && mv /opt/geckodriver /opt/geckodriver-$GK_VERSION \ && chmod 755 /opt/geckodriver-$GK_VERSION \ && ln -fs /opt/geckodriver-$GK_VERSION /usr/bin/geckodriver 

Making the following changes, based on what linked @Florent B., was a fix for him. Essentially, firefox-esr is version 52, and the -headless option for Firefox was released in version 55. I'm not sure which version of iceweasel is, but it is presumably earlier. In addition, versions of Firefox above 52 will not work without libgtk-3 . I assume that Debian 8 still has libgtk-2 , so it also needs to be installed. Mute viewing works fine with build-essential , libgtk-3-dev , wget and libgl1-mesa-glx on Debian 8.

+1
source

You should not install Firefox using the package manager. You can find all releases of firefox at the link below

https://download-installer.cdn.mozilla.net/pub/firefox/releases/

If you look at the Selenium Firefox Dockerfile

https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeFirefox/Dockerfile

They download the required version using

 wget --no-verbose -O /tmp/firefox.tar.bz2 $FIREFOX_DOWNLOAD_URL 

And for dependency problems, they run the following command

 apt-get -qqy --no-install-recommends install firefox 

And then uninstall the firefox package

 apt-get -y purge firefox 

This ensures that you do not have to worry about all the necessary dependencies. If you want, you can still get dependencies

 $ apt-cache depends firefox | grep Depends Depends: lsb-release Depends: libatk1.0-0 Depends: libc6 Depends: libcairo-gobject2 Depends: libcairo2 Depends: libdbus-1-3 Depends: libdbus-glib-1-2 Depends: libfontconfig1 Depends: libfreetype6 Depends: libgcc1 Depends: libgdk-pixbuf2.0-0 Depends: libglib2.0-0 Depends: libgtk-3-0 Depends: libpango-1.0-0 Depends: libpangocairo-1.0-0 Depends: libstartup-notification0 Depends: libstdc++6 Depends: libx11-6 Depends: libx11-xcb1 Depends: libxcb-shm0 Depends: libxcb1 Depends: libxcomposite1 Depends: libxdamage1 Depends: libxext6 Depends: libxfixes3 Depends: libxrender1 Depends: libxt6 

If you look at the link below

https://developer.mozilla.org/en-US/Firefox/Headless_mode

Browser support

Headless Firefox runs on Fx55 + on Linux and 56+ on Windows / Mac.

0
source

Source: https://habr.com/ru/post/1275611/


All Articles