How to implement "Selenium" using python

Sadly I could not make Chrome WebDriver work either, but using Firefox WebDriver works, I wrote this flake.nix file because stable-24.05 and unstable channels are outdated making firefox and geckodriver be incompatibles [ at least that happened in my workspace ].

{
  description = "Selenium Environment";

  inputs = {
    # using nixos-unstable because geckodriver is outdated in nixos-24.05
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:    
      let
        pkgs = import nixpkgs { inherit system; };
      in
      with pkgs;
      {
        devShells.default = mkShell {        
          buildInputs = [ firefox geckodriver ];

          # Somehow VSCode terminal pops up with "bash: __vsc_prompt_cmd_original: command not found"
          shellHook = ''
            unset PROMPT_COMMAND
          '';
        };
      }
    );
}

and respectively using the firefox driver in the Python code:

options = webdriver.FirefoxOptions()
# required for idx.dev because no user interface is available
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)

Otherwise we will have to wait for some solution If you really want to use the Chrome Web Driver.

1 Like