SeleniumHQ/selenium · error · OSError

Can't find java executable located at {java_path}

Error message

Can't find java executable located at {java_path}

What it means

Raised by the `java_path` setter when a path is supplied but `os.path.exists` reports it as absent. The server runner needs a real JRE binary to launch `java -jar <selenium-server>`, so it fails fast rather than producing a confusing Popen error later. It is an OSError.

Source

Thrown at py/selenium/webdriver/remote/server.py:156

    @property
    def env(self):
        return self._env

    @env.setter
    def env(self, env):
        if env is not None and not isinstance(env, collections.abc.Mapping):
            raise TypeError("env must be a mapping of environment variables")
        self._env = env

    @property
    def java_path(self):
        return self._java_path

    @java_path.setter
    def java_path(self, java_path):
        if java_path and not os.path.exists(java_path):
            raise OSError(f"Can't find java executable located at {java_path}")
        self._java_path = java_path

    def _wait_for_server(self, timeout=10):
        start = time.time()
        while time.time() - start < timeout:
            try:
                urllib.request.urlopen(self.status_url)
                return True
            except urllib.error.URLError:
                time.sleep(0.2)
        return False

    def download_if_needed(self, version=None):
        """Download the server if it doesn't already exist.

        Latest version is downloaded unless specified.
        """
        args = ["--grid"]

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Verify the path exists and points at the executable binary, not a directory.
  2. Run `which java` / `readlink -f $(which java)` to get the absolute resolved path.
  3. Omit java_path entirely so the runner falls back to shutil.which('java') from PATH.

Example fix

# before
server.java_path = '/opt/java'  # a directory

# after
import shutil
server.java_path = shutil.which('java')  # or an absolute binary path that exists
Defensive patterns

Strategy: validation

Validate before calling

import os
if java_path and not os.path.exists(java_path):
    raise FileNotFoundError(f'java not found at {java_path}')
server.java_path = java_path

Prevention

When it happens

Trigger: Setting `server.java_path = '/usr/lib/jvm/bin/java'` to a path that does not exist (typo, wrong install prefix, pointing at the JDK directory instead of the binary, or a relative path that doesn't resolve from the cwd).

Common situations: Hardcoding a java path from another machine/CI image. Using a Docker host path while running inside a container with a different mount. Pointing at the JAVA_HOME folder rather than the bin/java file.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/bf6328ad8d15e562. Report an issue: GitHub.