SeleniumHQ/selenium · error · TypeError

Binary Location Must be a String

Error message

Binary Location Must be a String

What it means

Raised by the binary_location setter on wpewebkit.Options when the assigned value is not a str. The error message comes from the inherited BINARY_LOCATION_ERROR constant ('Binary Location Must be a String') defined in selenium.webdriver.common.options. The getter returns self._binary_location (initialized to empty string ''), and to_capabilities() only includes the binary in capabilities if it is truthy (non-empty).

Source

Thrown at py/selenium/webdriver/wpewebkit/options.py:43

    def __init__(self) -> None:
        super().__init__()
        self._binary_location = ""

    @property
    def binary_location(self) -> str:
        """Return the location of the browser binary or an empty string."""
        return self._binary_location

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

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

    def to_capabilities(self) -> dict:
        """Create a capabilities dictionary with all set options."""
        caps = self._caps

        browser_options = {}
        if self.binary_location:
            browser_options["binary"] = self.binary_location
        if self.arguments:
            browser_options["args"] = self.arguments

        caps[Options.KEY] = browser_options

        return caps

    @property
    def default_capabilities(self) -> dict[str, str]:

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Convert to str before assignment: options.binary_location = str(path_obj).
  2. Pass a string literal: options.binary_location = '/usr/bin/WPEWebDriver'.
  3. If the path may be None, default to empty string: options.binary_location = path or ''.

Example fix

// before
from pathlib import Path
options.binary_location = Path('/usr/bin/WPEWebProcess')
// after
from pathlib import Path
options.binary_location = str(Path('/usr/bin/WPEWebProcess'))
Defensive patterns

Strategy: type-guard

Validate before calling

path = '/usr/bin/WPEWebDriver'  # or str(some_path_obj)
if not isinstance(path, str):
    path = str(path)
options.binary_location = path

Type guard

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

Try / catch

null

Prevention

When it happens

Trigger: Assigning options.binary_location = Path('/usr/bin/WPEWebProcess') (a pathlib.Path object) instead of a string; assigning None, an int, or any non-str type; passing a binary path from a variable that was not explicitly converted to str.

Common situations: Using pathlib.Path for file paths and forgetting to call str(); passing None as a sentinel for 'default' instead of empty string; reading path from environment or config that returns a non-string type; cross-binding code that passes a Path where str is expected.

Related errors


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