selenium-webdriver: The geckodriver executable could not be found on the current PATH

Viewed 3090

I installed the selenium webdriver using the following command:

$ npm i selenium-webdriver

Then, I created the directory D:\WebDriver\bin (and added the files geckodriver.exe and operadriver.exe to that directory) and added it to the system's PATH variables.

The PATH to the directory that contains both drivers was successfully added, as can be seen below:

$ printenv PATH
/mnt/d/WebDriver/bin/
$ ls "/mnt/d/WebDriver/bin/"
geckodriver.exe  operadriver.exe

I am also able to run the geckodriver via cmd.exe (Same applies to operadriver):

C:\Users\user>geckodriver
1621873805268   geckodriver     INFO    Listening on 127.0.0.1:4444

When I try to run one example file (google_search) via:

/mnt/d/proj/node_modules/selenium-webdriver/example $ node google_search.js

I receive the following stacktrace:

Error: The geckodriver executable could not be found on the current PATH. Please download the latest version from https://github.com/mozilla/geckodriver/releases/ and ensure it can be found on your PATH.

The operadriver also cannot be found when setting up an example that uses the opera driver.

Worth mentioning is that I use a Windows Subsystem for Linux (WSL) and ran the commands (node, printenv and npm) in the terminal of that subsystem. The path variable was set on the Windows system and the required drivers were only installed on the Windows system. I can access the installed files on my windows system via the WSL terminal, but selenium still cannot find the specific driver(s).

When I run the above mentioned test file (google_search.js) from selenium-webdriver on the Windows system, it does find the web driver and works as expected. I still cannot figure out the reason why the driver is not being found in the WSL.

1 Answers

I was able to resolve the problem using the following well written article: https://qxf2.com/blog/setup-linux-testing-environment-on-windows-using-wsl/. By creating symlinks that point to the driver and the web driver executable, the driver and the web browser was found. For now, I do think it's easier to run the tests in cmd.exe, though, as it does not require these additional steps.

Related