Python selenium driver chrome - WebDriverException: Message: 'chromedriver' executable needs to be in PATH

how to work with selenium in python on nixos?

from selenium import webdriver
driver = webdriver.Chrome()

results in


WebDriverException                        Traceback (most recent call last)
<ipython-input-3-04897e3af1b8> in <module>
      1 from Screenshot import Screenshot_Clipping
      2 from selenium import webdriver
----> 3 driver = webdriver.Chrome()
      4 
      5 

/nix/store/59hsifg8fpp52729wkqvi19wzz83n3k1-python3-3.7.9-env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
     71             service_args=service_args,
     72             log_path=service_log_path)
---> 73         self.service.start()
     74 
     75         try:

/nix/store/59hsifg8fpp52729wkqvi19wzz83n3k1-python3-3.7.9-env/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

We have a chromedriver package in Nixpkgs, which you can add to a package or project shell using the nativeBuildInputs argument.

# mkShell {
# or
# stdenv.mkDerivation {

  nativeBuildInputs = [ chromedriver ];

This will put chromedriver in PATH, as suggested by the error message.

If you’re not packaging anything and your project doesn’t have a Nix shell, and you just want to run the thing, you could add it to NixOS.

  environment.systemPackages = [ pkgs.chromedriver ];

or install it imperatively, as suggested on NixOS Search

Thanks for your answer
I think in my case the version(s) didn’t fit together …

1 Like

Hello I have the same issue but with pkgs.chromedriver I have this issue :
(The process started from chrome location /home/noah/.cache/selenium/chrome/linux64/131.0.6778.264/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
The problem indeed is that the path to chromedriver is not the expected one but I don’t find the solution, no matter how I try to specify the path I get an error.
This is my shell.nix :

{
  pkgs ? import <nixpkgs> { },
}:
pkgs.mkShell {
  packages = with pkgs; [
    python312Packages.selenium
    chromedriver
  ];

  shellHook = ''
    export DIRENV='selenium'
  '';
}