SeleniumHQ/selenium · error · Error

Missing required parameter: ${key}

Error message

Missing required parameter: ${key}

What it means

Thrown as a generic Error by webdriver.http.Executor.buildPath_() when a path template parameter (e.g. :sessionId, :id) has no corresponding value in the command's parameters object. The method iterates over path placeholders extracted from the URL template; for each, it looks up parameters[key]. If the key is absent, it throws 'Missing required parameter: <key>'. This is from the legacy Closure-based HTTP layer.

Source

Thrown at javascript/webdriver/http/http.js:161

webdriver.http.Executor.buildPath_ = function(path, parameters) {
  var pathParameters = path.match(/\/:(\w+)\b/g);
  if (pathParameters) {
    for (var i = 0; i < pathParameters.length; ++i) {
      var key = pathParameters[i].substring(2);  // Trim the /:
      if (key in parameters) {
        var value = parameters[key];
        // TODO: move webdriver.WebElement.ELEMENT definition to a
        // common file so we can reference it here without pulling in all of
        // webdriver.WebElement's dependencies.
        if (value && value['ELEMENT']) {
          // When inserting a WebElement into the URL, only use its ID value,
          // not the full JSON.
          value = value['ELEMENT'];
        }
        path = path.replace(pathParameters[i], '/' + value);
        delete parameters[key];
      } else {
        throw new Error('Missing required parameter: ' + key);
      }
    }
  }
  return path;
};


/**
 * Callback used to parse {@link webdriver.http.Response} objects from a
 * {@link webdriver.http.Client}.
 * @param {!webdriver.http.Response} httpResponse The HTTP response to parse.
 * @return {!bot.response.ResponseObject} The parsed response.
 * @private
 */
webdriver.http.Executor.parseHttpResponse_ = function(httpResponse) {
  try {
    return /** @type {!bot.response.ResponseObject} */ (JSON.parse(
        httpResponse.body));

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Ensure every path-template parameter is set on the command: command.setParameter('sessionId', sessionId) and command.setParameter('id', elementId).
  2. If using WebElement objects in parameters, confirm they carry a valid element ID (the code checks for value['ELEMENT'] to extract the ID).
  3. Verify the session has been created before issuing session-scoped commands — the sessionId must be populated.
  4. Log command.getParameters() before execute() to confirm all required keys are present.

Example fix

// before
var cmd = new webdriver.command.Command(
  webdriver.command.Name.FIND_CHILD_ELEMENT
)
// missing 'id' parameter
executor.execute(cmd)

// after
var cmd = new webdriver.command.Command(
  webdriver.command.Name.FIND_CHILD_ELEMENT
)
cmd.setParameter('sessionId', session.getId())
cmd.setParameter('id', element.getId())
cmd.setParameter('using', 'css selector')
cmd.setParameter('value', '.child')
executor.execute(cmd)
Defensive patterns

Strategy: validation

Validate before calling

function validateParams(command, requiredKeys) {
  const params = command.getParameters()
  for (const key of requiredKeys) {
    if (!(key in params) || params[key] == null) {
      throw new Error('Missing path param: ' + key)
    }
  }
}

Try / catch

try {
  executor.execute(command)
} catch (e) {
  if (/Missing required parameter/.test(e.message)) {
    // set the missing parameter and retry
  } else throw e
}

Prevention

When it happens

Trigger: Executing a command whose path template contains a placeholder (like /session/:sessionId/element/:id) but the command's parameters object does not include a value for 'sessionId' or 'id'. The buildPath_ function cannot substitute the placeholder.

Common situations: Constructing a Command manually without setting all required path parameters via setParameter(); a WebElement reference whose ELEMENT/element-6066-11e4-a52e-4f7994e6c44e ID is missing; calling a command before a session has been established (so sessionId is not populated).

Related errors


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