How to fix selenium (python package) locally?

in NixOS 22.11 the selenium python package is broken.

There is already an issue pythonPackages.selenium: FileNotFoundError: [Errno 2] No such file or directory, 'getAttribute.js' · Issue #181035 · NixOS/nixpkgs · GitHub

I want to fix it locally in my shell.nix by overriding postInstall.

{ pkgs ? import <nixpkgs> { } }:

let

  python-with-my-packages = (let
    python = let
      packageOverrides = self: super: {
        selenium = super.selenium.overridePythonAttrs (old: rec {
          postInstall = ''
            install -Dm 755 ../rb/lib/selenium/webdriver/atoms/getAttribute.js $out/${self.sitePackages}/selenium/webdriver/remote/getAttribute.js
            install -Dm 755 ../rb/lib/selenium/webdriver/atoms/isDisplayed.js $out/${self.sitePackages}/selenium/webdriver/remote/isDisplayed.js
          '';

        });
      };
    in pkgs.python3.override {
      inherit packageOverrides;
      self = python;
    };

  in python.withPackages (ps: [ ps.selenium ])).passthru.pkgs.selenium;

in pkgs.mkShell {
  buildInputs = [
    python-with-my-packages

    pkgs.geckodriver

  ];

}

But is says, error: attribute ‘sitePackages’ missing. Where can I find this attribute, and how can learn how to find this attribute?

Did it work for you finally?

unfortunately not, here my Nix skills lack, so I pinned it to a 22.05 version of nixpkgs as workaround

For your information, this overlay finally worked for me:

with import <nixpkgs> {};

let
  python = let 
    packageOverrides = prev: final: {
      selenium = final.selenium.overridePythonAttrs (old: {
        src = fetchFromGitHub {
          owner = "SeleniumHQ";
          repo = "selenium";
          rev = "refs/tags/selenium-4.8.0";
          hash = "sha256-YTi6SNtTWuEPlQ3PTeis9osvtnWmZ7SRQbne9fefdco=";
        };
        postInstall = ''
          install -Dm 755 ../rb/lib/selenium/webdriver/atoms/getAttribute.js $out/${python3Packages.python.sitePackages}/selenium/webdriver/remote/getAttribute.js
          install -Dm 755 ../rb/lib/selenium/webdriver/atoms/isDisplayed.js $out/${python3Packages.python.sitePackages}/selenium/webdriver/remote/isDisplayed.js
        '';
      });
    }; in python3.override { inherit packageOverrides; };
in mkShell {
  packages = [
    (python.withPackages (
      ps: with ps; [
	pandas
	requests
	selenium
      ]))
  ];
}
2 Likes