1

I'm trying to run a python script with Selenium inside docker. Since the script is in a docker container, I keep getting this error:

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

The code works just fine, when I run it on my computer and use the PATH to the chromedriver file, however a docker container can't see the PATH as it is isolated. I would use a pre-made docker image, however I need other dependencies for my code to run such as smtplib, imapclient, and beautifulsoup to name a few.

Is there a command that will tell Selenium that the chromedriver is in the same folder as the script, or some other way to make it visible to docker?

2 Answers 2

1

Docker container is a like a VM. Inside the image you have scripts. But not chromedriver. I would say do not copy the chromedriver inside the image. Just copying the chromedriver alone will not work.

Instead use selenium/node-chrome image and give the container name as the host to your container.

Take a look at this example.

http://www.testautomationguru.com/selenium-webdriver-how-to-run-multiple-test-suites-using-docker-compose/

Sign up to request clarification or add additional context in comments.

2 Comments

My apologies, I forgot to mention the other dependencies my program has. Is there a way I can view the dockerfile for this docker image?
@Toby Here's a link to the docker file for selenium/node-chrome on github: selenium/node-chrome
0

You could use the following code snippet to set the path to the chrome driver within your script:

import os

path_to_chrome_driver = os.path.join(os.getcwd(), 'chromedriver.exe')
browser = webdriver.Chrome(executable_path=path_to_chrome_driver )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.