3

I'm trying to run Selenium on alpine 3.6 container (FROM alpine:3.6).

What I'm trying in container shell:

apk update
apk add python3
pip3 install -U selenium
apk add chromium
apk add chromium-driver

And running the following python (using python3):

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'usr/bin/chromedriver') # Thrown an exception

And got the following exception:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed (Driver info: chromedriver=2.27 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 5.0.0-23-generic x86_64)

selenium=3.141.0
chromium=57.0.2987.133
chromeDriver=2.27

How can I solve it?

Evyatar
  • 1,107
  • 2
  • 13
  • 36
  • Please post some more info like chrome browser version and selenium version as well.Seems like this is a compatible issue you need to have compatible version of webdriver.you can see following link to check which chrome driver supports the chrome version https://chromedriver.chromium.org/downloads – KunduK Jan 16 '20 at 23:03
  • @KunduK, see my edit with selenium, chromium versions – Evyatar Jan 16 '20 at 23:08
  • 1
    I would suggest you to upgrade both chrome driver and browser to latest version.This seems very old version you are using.I haven’t work on that platform so don’t know how to upgrade.however you might know how to upgrade and see if you can crack that. – KunduK Jan 16 '20 at 23:15

2 Answers2

7

Solved by the followings steps (Work with alpine3.6):

Update the repositores:

echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" > /etc/apk/repositories
echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories

Apk Update:

apk update

Install chromium & chromedriver:

apk add chromium
apk add chromium-chromedriver

Install python3, selenium:

apk add python3
pip3 install -U selenium

And the following python code works for me:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get('http://example.com')
Evyatar
  • 1,107
  • 2
  • 13
  • 36
1

this is what I did to get selenium to work with alpine3.9 and firefox, hopefull this is helpful

took me a long time to figure out the perfect versions

geckodriver must be version 0.21.0

Dockerfile

FROM python:alpine3.9
RUN apk update
RUN apk add firefox-esr
RUN apk add xvfb
RUN pip install -r requirements.txt

requirements.txt

selenium==3.11
pyvirtualdisplay==0.2.1

python code

from selenium.webdriver.firefox.options import Options
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
Marc Frame
  • 923
  • 1
  • 13
  • 26
  • you will need 0.21.0 I think https://github.com/mozilla/geckodriver/releases/tag/v0.21.0, and you are using pyvirtualdisplay? – Marc Frame Jan 17 '20 at 00:31
  • you need to specify the path for it, you can do that with this argument `executable_path=GECKO_DRIVER_PATH` in the webdriver.Firefox call with GECKOD_DRIVER_PATH being a string – Marc Frame Jan 17 '20 at 01:08
  • did this work for you? if so mark the answer as correct – Marc Frame Jan 20 '20 at 21:13