How to get chromedriver to work in bitbucket pipeline?

I’m trying to run a selenium script in a bitbucket pipeline. I’ve tried both putting the chromedriver in the repo and using ChromeDriverManager, both have resulted in the respective errors:

FileNotFoundError: [Errno 2] No such file or directory: ‘chromedriver.exe’

selenium.common.exceptions.WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/99.0.4844.51/chromedriver unexpectedly exited. Status code was: 127

The selenium script, bitbucket-pipelines.yml and chromedriver.exe files are in the same directory of the repo for the first error.

Below are my pipeline and selenium scripts:

pipeline:

 - step:
        name: Get latest versions of libraries
        image: python:3.8.2
        script:
          - pip install selenium
          - pip install beautifulsoup4
          - pip install lxml
          - pip install webdriver-manager
          - python webscrape.py #selenium script
        artifacts:
          - latest_vers.json

selenium script:

if __name__ == '__main__':
    # s = Service("chromedriver.exe")
    # driver = webdriver.Chrome(service=s)
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
    driver.maximize_window()
    driver.get("https://www.npmjs.com/")
    ...

What should I do?

Hey there :wave:,

In the first lines (s = Service("chromedriver.exe")), you try to execute a .exe. As bitbucket-pipelines are using docker and therefore linux, .exe-files can’t be executed.

Furthermore, you are using python:3.8.2 as your docker-container. this container probably does not have chrome installed. This explains, why your second try also does not work.

You could either install chrome to this container, or use a container that already comes with chrome. Selenium themselves seems to offer a container for this: Docker Hub . keep in mind though that i never tried this container. I also don’t know if it has python installed. It’s worth a try I guess.

1 Like