{"record":{"id":"a9ed6fd9602b8562","repo":"angular/components","slug":"this-testelement-was-not-created-by-the-webdriverh","errorCode":null,"errorMessage":"This TestElement was not created by the WebDriverHarnessEnvironment","messagePattern":"This TestElement was not created by the WebDriverHarnessEnvironment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cdk/testing/selenium-webdriver/selenium-web-driver-harness-environment.ts","lineNumber":95,"sourceCode":"\n  /** Environment stabilization callback passed to the created test elements. */\n  private _stabilizeCallback: () => Promise<void>;\n\n  protected constructor(\n    rawRootElement: () => webdriver.WebElement,\n    options?: WebDriverHarnessEnvironmentOptions,\n  ) {\n    super(rawRootElement);\n    this._options = {...defaultEnvironmentOptions, ...options};\n    this._stabilizeCallback = () => this.forceStabilize();\n  }\n\n  /** Gets the ElementFinder corresponding to the given TestElement. */\n  static getNativeElement(el: TestElement): webdriver.WebElement {\n    if (el instanceof SeleniumWebDriverElement) {\n      return el.element();\n    }\n    throw Error('This TestElement was not created by the WebDriverHarnessEnvironment');\n  }\n\n  /** Creates a `HarnessLoader` rooted at the document root. */\n  static loader(\n    driver: webdriver.WebDriver,\n    options?: WebDriverHarnessEnvironmentOptions,\n  ): HarnessLoader {\n    return new SeleniumWebDriverHarnessEnvironment(\n      () => driver.findElement(webdriver.By.css('body')),\n      options,\n    );\n  }\n\n  /**\n   * Flushes change detection and async tasks captured in the Angular zone.\n   * In most cases it should not be necessary to call this manually. However, there may be some edge\n   * cases where it is needed to fully flush animation events.\n   */","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/testing/selenium-webdriver/selenium-web-driver-harness-environment.ts#L77-L113","documentation":"Thrown by the static WebDriverHarnessEnvironment.getNativeElement when the TestElement is not a SeleniumWebDriverElement. Only elements created by this environment wrap a webdriver.WebElement and can be unwrapped.","triggerScenarios":"Calling WebDriverHarnessEnvironment.getNativeElement(testElement) with a TestbedHarnessElement or ProtractorElement, i.e. an element created by a different harness environment.","commonSituations":"Shared helpers passing TestElements between unit-test (TestBed) and Selenium e2e code paths; mixing harness environments in one test suite.","solutions":["Create the element through WebDriverHarnessEnvironment (rootEl/driver based loaders) before unwrapping.","Check el instanceof SeleniumWebDriverElement before calling getNativeElement.","Use the environment-specific unwrap helper that matches the element's origin."],"exampleFix":"// before\nconst webEl = WebDriverHarnessEnvironment.getNativeElement(el);\n// after\nif (el instanceof SeleniumWebDriverElement) {\n  const webEl = WebDriverHarnessEnvironment.getNativeElement(el);\n}","handlingStrategy":"type-guard","validationCode":"import {SeleniumWebDriverElement} from '@angular/cdk/testing/selenium-webdriver';\nif (!(el instanceof SeleniumWebDriverElement)) throw new TypeError('el must come from WebDriverHarnessEnvironment');","typeGuard":"const isSeleniumElement = (el: TestElement): el is SeleniumWebDriverElement => el instanceof SeleniumWebDriverElement;","tryCatchPattern":"let webEl: webdriver.WebElement | undefined;\ntry { webEl = WebDriverHarnessEnvironment.getNativeElement(el); } catch { webEl = undefined; }","preventionTips":["Track which harness environment created each TestElement","Do not share TestElement instances across TestBed/Protractor/WebDriver suites","instanceof-check before unwrapping"],"tags":["angular-cdk","testing","selenium-webdriver","type-mismatch"],"backgroundTag":"incompatible-test-element-type","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}