2

I'm trying to run selenium in an alpine docker. I allready managed it FROM python:3 but it would be nice to save that disk space.

I get the error
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
and FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
Googling this only gives "Put geckodriver in your $PATH" and "Add folder path of geckodriver to $PATH with PATH=$PATH:/usr/src/app"

But geckodriver is in $PATH and it still results in the same error.

I also tried adding the executable as argument to the driver = webdriver.Firefox() but it changed nothing.
WebDriverException: 'geckodriver' executable needs to be in PATH even though it is (1 answer)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH with GeckoDriver Selenium Firefox (2 answers)
Python 3.5 - “Geckodriver executable needs to be in PATH” (4 answers)

Dockerfile:

FROM frolvlad/alpine-python3
WORKDIR /usr/src/app
COPY . .
RUN tar -xzf geckodriver-v0.26.tar.gz && cp geckodriver /bin

RUN pip install --no-cache-dir -r requirements.txt
RUN apk add --no-cache firefox-esr xvfb
ENV DISPLAY=:1.0

ENTRYPOINT ["./entrypoint.sh"]

entrypoint.sh

Xvfb :1 -screen 0 1024x768x16 &> xvfb.log &
python ./seleniumTest.py

output:

/usr/src/app # echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/src/app:/usr/src/app
/usr/src/app # which geckodriver
/bin/geckodriver
/usr/src/app # type geckodriver
geckodriver is /bin/geckodriver
/usr/src/app # ls -l /bin/geckodriver
-rwxr-xr-x    1 root     root       7008696 Mar  3 18:29 /bin/geckodriver
/usr/src/app # ./entrypoint.sh
xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./seleniumTest.py", line 8, in <module>
    driver= webdriver.Firefox()
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/usr/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

seleniumTest.py:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1024, 768))
display.start()

url = 'https://stackoverflow.com/questions/15018372/how-to-take-partial-screenshot-with-selenium-webdriver-in-python'
driver= webdriver.Firefox()

driver.get(url)

element = driver.find_element_by_css_selector('#question-header')
image = element.screenshot('screenshot.png')
MatzE
  • 78
  • 8
  • 2
    If other googlers see this: All the questions this was marked a duplicate for have been tried before. I should have included it. The Question which solved this problem was a different one: https://stackoverflow.com/questions/58738920/running-geckodriver-in-an-alpine-docker-container – MatzE Mar 03 '20 at 22:27

0 Answers0