SeleniumHQ/selenium · error · FileNotFoundError

Could not find findElements.js in package {_pkg}

Error message

Could not find findElements.js in package {_pkg}

What it means

Raised in `find_elements` (RelativeBY branch) when `pkgutil.get_data(_pkg, 'findElements.js')` returns None — the bundled JS atom that implements relative locators could not be loaded from the package. This is almost always a corrupted/partial install (the file is part of the wheel) rather than caller error. It is a FileNotFoundError.

Source

Thrown at py/selenium/webdriver/remote/webdriver.py:934

            by: The locating strategy to use. Default is `By.ID`. Supported
                values include: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR,
                By.CLASS_NAME, By.TAG_NAME, By.LINK_TEXT, By.PARTIAL_LINK_TEXT,
                or RelativeBy.
            value: The locator value to use with the specified `by` strategy.

        Returns:
            List of WebElements matching locator strategy found on the page.

        Example:
            `element = driver.find_elements(By.ID, 'foo')`
        """
        by, value = self.locator_converter.convert(by, value)

        if isinstance(by, RelativeBy):
            _pkg = ".".join(__name__.split(".")[:-1])
            raw_data = pkgutil.get_data(_pkg, "findElements.js")
            if raw_data is None:
                raise FileNotFoundError(f"Could not find findElements.js in package {_pkg}")
            raw_function = raw_data.decode("utf8")
            find_element_js = f"/* findElements */return ({raw_function}).apply(null, arguments);"
            return self.execute_script(find_element_js, by.to_dict())

        # Return empty list if driver returns null
        # See https://github.com/SeleniumHQ/selenium/issues/4555
        return self.execute(Command.FIND_ELEMENTS, {"using": by, "value": value})["value"] or []

    @property
    def capabilities(self) -> dict:
        """Returns the drivers current capabilities being used."""
        return self.caps

    def get_screenshot_as_file(self, filename) -> bool:
        """Save a screenshot of the current window to a PNG image file.

        Returns:
            False if there is any IOError, else returns True. Use full paths in your filename.

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Reinstall selenium cleanly: pip install --force-reinstall selenium.
  2. For editable/source checkouts, run the build so atoms are present, then reinstall.
  3. For frozen apps, ensure selenium's package data (*.js) is included by the packager.

Example fix

# before
# corrupted install; findElements.js missing
driver.find_elements(with_tag('button').near(el))

# after (reinstall)
# pip install --force-reinstall selenium
driver.find_elements(with_tag('button').near(el))
Defensive patterns

Strategy: try-catch

Try / catch

try:
    driver.find_elements(rel_by)
except FileNotFoundError:
    # selenium package data missing; reinstall selenium and retry

Prevention

When it happens

Trigger: Calling driver.find_elements(with_tag(...)) on an environment where the selenium package is missing its data files: an incomplete pip install, a broken editable install, a stripped/frozen package that excluded package_data, or running from a source tree without the generated atom.

Common situations: Editable installs (pip install -e) missing package_data; PyInstaller/cx_Freeze builds that didn't include *.js data; manually deleting files under site-packages; installing from a partial sdist.

Related errors


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