{"record":{"id":"85697dcb56de9f7a","repo":"SeleniumHQ/selenium","slug":"cannot-locate-an-element-with-provided-parameters","errorCode":null,"errorMessage":"Cannot locate an element with provided parameters","messagePattern":"Cannot locate an element with provided parameters","errorType":"exception","errorClass":"NoSuchElementError","httpStatus":404,"severity":"error","filePath":"javascript/selenium-webdriver/lib/webdriver.js","lineNumber":1032,"sourceCode":"        .setParameter('value', locator.value)\n    }\n\n    id = this.execute(cmd)\n    if (locator instanceof RelativeBy) {\n      return this.normalize_(id)\n    } else {\n      return new WebElementPromise(this, id)\n    }\n  }\n\n  /**\n   * @param {!Function} webElementPromise The webElement in unresolved state\n   * @return {!Promise<!WebElement>} First single WebElement from array of resolved promises\n   */\n  async normalize_(webElementPromise) {\n    let result = await webElementPromise\n    if (result.length === 0) {\n      throw new NoSuchElementError('Cannot locate an element with provided parameters')\n    } else {\n      return result[0]\n    }\n  }\n\n  /**\n   * @param {!Function} locatorFn The locator function to use.\n   * @param {!(WebDriver|WebElement)} context The search context.\n   * @return {!Promise<!WebElement>} A promise that will resolve to a list of\n   *     WebElements.\n   * @private\n   */\n  async findElementInternal_(locatorFn, context) {\n    let result = await locatorFn(context)\n    if (Array.isArray(result)) {\n      if (result.length === 0) {\n        throw new NoSuchElementError('Cannot locate an element with provided parameters')\n      }","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/webdriver.js#L1014-L1050","documentation":"Thrown as a NoSuchElementError by WebDriver.normalize_() when a locator function resolves to an empty array. This method is invoked by the singular findElement() flow: it resolves the locator promise, expects a list of WebElements, and throws if that list has zero entries. It represents the W3C WebDriver 'no such element' condition when the JavaScript locator itself returns nothing before any remote round-trip.","triggerScenarios":"Calling driver.findElement(locator) or element.findElement(locator) where the underlying locator function (e.g. By.js, a custom locator, or js-based locator) returns an array with length 0. Specifically, normalize_() is called on the unresolved webElementPromise; if `await webElementPromise` yields an empty array, the error fires.","commonSituations":"Page has not loaded the target element yet (no explicit wait), element selector changed after a UI refactor, the locator targets a dynamically-rendered component that is conditionally absent, or a custom locator function returns [] for a page state the test did not anticipate.","solutions":["Replace findElement() with findElements() and check the returned array length before indexing, so an empty result does not throw.","Add an explicit wait using webdriver.until.elementLocated(locator) before calling findElement(), giving the page time to render the element.","Verify the locator strategy and selector against the current DOM using browser devtools — a stale class name or changed structure is the most frequent cause.","If the element is legitimately optional, wrap the call in a try/catch for NoSuchElementError and handle the absence gracefully."],"exampleFix":"// before\nelement = await driver.findElement(By.css('.maybe-missing'))\n\n// after\nconst elements = await driver.findElements(By.css('.maybe-missing'))\nif (elements.length === 0) {\n  console.log('Element not present; skipping')\n} else {\n  element = elements[0]\n}\n// or with a wait:\nelement = await driver.wait(\n  webdriver.until.elementLocated(By.css('.maybe-missing')), 5000\n)","handlingStrategy":"validation","validationCode":"// Use findElements instead of findElement to avoid the throw\nconst elements = await driver.findElements(locator)\nif (elements.length > 0) {\n  const element = elements[0] // safe\n}","typeGuard":"// Check array before treating as single element\nfunction hasElement(arr) {\n  return Array.isArray(arr) && arr.length > 0\n}","tryCatchPattern":"try {\n  const el = await driver.findElement(locator)\n} catch (e) {\n  if (e instanceof webdriver.error.NoSuchElementError) {\n    // element legitimately absent\n  } else throw e\n}","preventionTips":["Prefer findElements() + length check over findElement() when absence is possible.","Always use explicit waits (driver.wait) before findElement() for dynamically loaded content.","Verify selectors against current DOM before running tests."],"tags":["javascript","locators","find-element","webdriver","no-such-element"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}