SeleniumHQ/selenium · error · TypeError

Binary Location Must be a String

Error message

Binary Location Must be a String

What it means

The `binary_location` setter on `chromium.options.ChromiumOptions` enforces that the value is a `str`. It stores the path to the browser executable (Chrome/Chromium/Edge). Any non-string (Path object, None, int) is rejected with `BINARY_LOCATION_ERROR` ("Binary Location Must be a String"). Note the inconsistent Title Case of this message versus other validators.

Source

Thrown at py/selenium/webdriver/chromium/options.py:52

        self._extensions: list[str] = []
        self._experimental_options: dict[str, str | int | dict | list[str]] = {}
        self._debugger_address: str | None = None
        self._enable_webextensions: bool = False

    @property
    def binary_location(self) -> str:
        """Returns the location of the binary, otherwise an empty string."""
        return self._binary_location

    @binary_location.setter
    def binary_location(self, value: str) -> None:
        """Allows you to set where the chromium binary lives.

        Args:
            value: Path to the Chromium binary.
        """
        if not isinstance(value, str):
            raise TypeError(self.BINARY_LOCATION_ERROR)
        self._binary_location = value

    @property
    def debugger_address(self) -> str | None:
        """Returns the address of the remote devtools instance."""
        return self._debugger_address

    @debugger_address.setter
    def debugger_address(self, value: str) -> None:
        """Set the address of the remote devtools instance for active wait connection.

        Args:
            value: Address of remote devtools instance if any (hostname[:port]).
        """
        if not isinstance(value, str):
            raise TypeError("Debugger Address must be a string")
        self._debugger_address = value

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Convert the Path to a string: `options.binary_location = str(pathlib.Path("/usr/bin/chromium"))`.
  2. Pass a raw string: `options.binary_location = "/usr/bin/chromium"`.
  3. Leave it unset to let Selenium Manager locate the browser automatically.

Example fix

// before
import pathlib
options.binary_location = pathlib.Path("/usr/bin/chromium")  # TypeError
// after
options.binary_location = str(pathlib.Path("/usr/bin/chromium"))
Defensive patterns

Strategy: validation

Validate before calling

import pathlib
p = pathlib.Path("/usr/bin/chromium")
binary = str(p) if not isinstance(p, str) else p
assert isinstance(binary, str), "binary_location must be str"
options.binary_location = binary

Type guard

def is_binary_location(value) -> bool:
    return isinstance(value, str)

Try / catch

try:
    options.binary_location = path
except TypeError:
    options.binary_location = str(path)

Prevention

When it happens

Trigger: `options.binary_location = pathlib.Path("/usr/bin/chromium")` (a pathlib.Path, not a str), `options.binary_location = None`, `options.binary_location = 123`. Passing a Path object is the most common hit because modern Python code tends to use pathlib.

Common situations: Using `pathlib.Path` instead of a plain string. Copying a snippet that assigns `None` to disable. Cross-binding habits (other Selenium bindings accept Path-like objects).

Related errors


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