Home > Back-end >  The file ChromeDriver does not exist when running on Docker
The file ChromeDriver does not exist when running on Docker

Time:10-02

I'm trying to run Selenium on Docker using Azure Function in C#. I've installed Selenium.WebDriver and Selenium.WebDriver.ChromeDriver nuget packages. In docker file I've also put code for installing Chrome driver, but when I try to create ChromeDriver in code, I get exception that chromedriver can't be found.

When I list all files in directory, I can see that there is chromedriver.exe file listed: enter image description here

but when I try to create a new Chrome driver using this line:

IWebDriver driver = new ChromeDriver(Environment.CurrentDirectory);

I get the following exception:

The file /home/site/wwwroot/bin/Debug/netcoreapp3.1/chromedriver does not exist. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html.

Why chromedriver.exe file is not recognized? When I run the same code without Docker, everything works fine.

CodePudding user response:

Add the absolute path of chromedriver.exe to container PATH environment variable

CodePudding user response:

Typically Windows executables end with .exe while Linux executables have no file extension. A file being executable on Linux is a consequence of file permissions rather than some naming convention.

The file path in the exception message uses forward-slashes / as file path delimiters rather than back slashes \ leading me to believe you have downloaded a Windows-compatible ChromeDriver which you are attempting to run on a Linux machine.

Solution: download the Linux driver instead when deployed via Docker.

  • Related