SeleniumHQ/selenium · critical · Error::WebDriverError

Unsuccessful command executed: #{command} - Code #{code}\n#{

Error message

Unsuccessful command executed: #{command} - Code #{code}\n#{result}\n#{stderr}

What it means

Raised by SeleniumManager.validate_command_result when the selenium-manager binary exits with a positive (non-zero) exit code, or when the result is nil (no valid JSON output). The message includes the exit code, stdout (parsed result), and stderr from the binary, providing diagnostic detail about why driver resolution failed.

Source

Thrown at rb/lib/selenium/webdriver/common/selenium_manager.rb:118

          json_output['logs'].each do |log|
            level = log['level'].casecmp('info').zero? ? 'debug' : log['level'].downcase
            WebDriver.logger.send(level, log['message'], id: :selenium_manager)
          end

          json_output['result']
        end

        def validate_command_result(command, status, result, stderr)
          if status.nil? || status.exitstatus.nil?
            WebDriver.logger.info("No exit status for: #{command}. Assuming success if result is present.",
                                  id: :selenium_manager)
          end

          return unless status&.exitstatus&.positive? || result.nil?

          code = status&.exitstatus || 'exit status not available'
          raise Error::WebDriverError,
                "Unsuccessful command executed: #{command} - Code #{code}\n#{result}\n#{stderr}"
        end
      end
    end # SeleniumManager
  end # WebDriver
end # Selenium

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Read the stderr/result in the error message: it typically states the exact reason (browser not found, download failed, version mismatch).
  2. Pre-install the correct driver and specify its path via Service.driver_path= to bypass Selenium Manager.
  3. Ensure the browser is installed and discoverable (check PATH, check the expected install location).
  4. If behind a proxy, set HTTP_PROXY/HTTPS_PROXY environment variables so selenium-manager can download drivers.
  5. Upgrade the selenium-webdriver gem to get a newer selenium-manager binary with broader compatibility.

Example fix

// before
# selenium-manager fails: cannot find matching chromedriver
options = Selenium::WebDriver::Options.chrome
driver = Selenium::WebDriver.for :chrome, options: options

// after (specify driver explicitly)
service = Selenium::WebDriver::Service.chrome(driver_path: '/usr/local/bin/chromedriver-120')
options = Selenium::WebDriver::Options.chrome
driver = Selenium::WebDriver.for :chrome, service: service, options: options
Defensive patterns

Strategy: try-catch

Validate before calling

# Pre-validate browser presence before launching driver
def browser_installed?(browser)
  case browser
  when :chrome
    system('which google-chrome google-chrome-stable chromium chromium-browser 2>/dev/null', out: '/dev/null')
  when :firefox
    system('which firefox 2>/dev/null', out: '/dev/null')
  else
    false
  end
end

Try / catch

begin
  driver = Selenium::WebDriver.for :chrome
rescue Selenium::WebDriver::Error::WebDriverError => e
  raise unless e.message.include?('Unsuccessful command executed')
  # parse the stderr in the message for diagnostics
  warn "Selenium Manager failed: #{e.message}"
  service = Selenium::WebDriver::Service.chrome(driver_path: ENV.fetch('CHROMEDRIVER_PATH'))
  driver = Selenium::WebDriver.for(:chrome, service: service)
end

Prevention

When it happens

Trigger: The binary runs but cannot find a suitable browser or driver (e.g., Chrome is not installed). The binary cannot download a driver due to network restrictions. Browser and driver version mismatch. The binary outputs invalid JSON or an error message in the result field. Firewall/proxy blocking the driver download endpoint.

Common situations: Running in CI without a browser pre-installed and no network access for auto-download. Corporate proxy blocking driver downloads. Browser updated but the cached driver is incompatible. Running on an architecture where no matching driver exists (e.g., ARM Linux with Chrome for x86).

Related errors


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