SeleniumHQ/selenium · error · Error::WebDriverError

not a file: #{path.inspect}

Error message

not a file: #{path.inspect}

What it means

assert_file raises WebDriverError when the given path does not exist as a regular file. It is used to validate driver executable paths before launch (assert_executable calls it first). A directory, a missing path, or a broken symlink all trigger this error.

Source

Thrown at rb/lib/selenium/webdriver/common/platform.rb:136

        `cygpath #{flags.join ' '} "#{path}"`.strip
      end

      def unix_path(path)
        path.tr(File::ALT_SEPARATOR, File::SEPARATOR)
      end

      def windows_path(path)
        path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
      end

      def make_writable(file)
        File.chmod 0o766, file
      end

      def assert_file(path)
        return if File.file? path

        raise Error::WebDriverError, "not a file: #{path.inspect}"
      end

      def assert_executable(path)
        assert_file(path)

        return if File.executable? path

        raise Error::WebDriverError, "not executable: #{path.inspect}"
      end

      def exit_hook
        pid = Process.pid

        at_exit { yield if Process.pid == pid }
      end

      def localhost
        info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Verify the path exists with File.file?(path) and correct it.
  2. Let Selenium Manager auto-manage the driver by not setting a manual driver_path.
  3. Use an absolute path to avoid working-directory ambiguity.
  4. Ensure the driver binary is downloaded to the configured location in CI.

Example fix

# before
Selenium::WebDriver::Chrome::Service.driver_path = '/wrong/path/chromedriver'

# after (let Selenium Manager handle it)
Selenium::WebDriver::Chrome::Service.driver_path = nil
# or point to the real file
Selenium::WebDriver::Chrome::Service.driver_path = '/usr/local/bin/chromedriver'
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, "driver not found at #{path}" unless path && File.file?(path)

Type guard

def driver_file?(path)
  !path.nil? && File.file?(path)
end

Try / catch

begin
  Selenium::WebDriver::Chrome::Service.driver_path = path
  Selenium::WebDriver.for(:chrome)
rescue Selenium::WebDriver::Error::WebDriverError => e
  raise unless e.message.include?('not a file')
  Selenium::WebDriver.for(:chrome) # let Selenium Manager auto-resolve
end

Prevention

When it happens

Trigger: Pointing a Service or DriverFinder at a path that does not exist. Setting driver path via Selenium::WebDriver::Chrome::Service.driver_path= to a wrong location. Passing a directory path where a binary file is expected.

Common situations: Driver binary not downloaded/installed. Typo in the configured path. Path is correct on one machine but missing in CI. Using a relative path that resolves differently.

Related errors


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