{"record":{"id":"97fc84bb3d3106d5","repo":"angular/components","slug":"this-testelement-was-not-created-by-the-protractor","errorCode":null,"errorMessage":"This TestElement was not created by the ProtractorHarnessEnvironment","messagePattern":"This TestElement was not created by the ProtractorHarnessEnvironment","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cdk/testing/protractor/protractor-harness-environment.ts","lineNumber":56,"sourceCode":"  protected constructor(\n    rawRootElement: ElementFinder,\n    options?: ProtractorHarnessEnvironmentOptions,\n  ) {\n    super(rawRootElement);\n    this._options = {...defaultEnvironmentOptions, ...options};\n  }\n\n  /** Creates a `HarnessLoader` rooted at the document root. */\n  static loader(options?: ProtractorHarnessEnvironmentOptions): HarnessLoader {\n    return new ProtractorHarnessEnvironment(protractorElement(by.css('body')), options);\n  }\n\n  /** Gets the ElementFinder corresponding to the given TestElement. */\n  static getNativeElement(el: TestElement): ElementFinder {\n    if (el instanceof ProtractorElement) {\n      return el.element;\n    }\n    throw Error('This TestElement was not created by the ProtractorHarnessEnvironment');\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   */\n  async forceStabilize(): Promise<void> {}\n\n  /** @docs-private */\n  async waitForTasksOutsideAngular(): Promise<void> {\n    // TODO: figure out how we can do this for the protractor environment.\n    // https://github.com/angular/components/issues/17412\n  }\n\n  /** Gets the root element for the document. */\n  protected getDocumentRoot(): ElementFinder {\n    return protractorElement(by.css('body'));","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/cdk/testing/protractor/protractor-harness-environment.ts#L38-L74","documentation":"Thrown by the static ProtractorHarnessEnvironment.getNativeElement when the TestElement passed in is not a ProtractorElement. Only elements created by the Protractor harness environment wrap a Protractor ElementFinder; anything else cannot be unwrapped.","triggerScenarios":"Calling ProtractorHarnessEnvironment.getNativeElement(testElement) where testElement came from TestbedHarnessEnvironment (unit-test TestElement), SeleniumWebDriverElement, or a mock/custom TestElement implementation.","commonSituations":"Shared test utilities that pass TestElements across environments (TestBed harnesses in one project, Protractor e2e in another); copy-pasting a helper from unit tests into Protractor specs.","solutions":["Obtain the TestElement from the Protractor harness environment (e.g. via ProtractorHarnessEnvironment.loader() based harnesses) before unwrapping.","Check el instanceof ProtractorElement before calling getNativeElement.","Switch the helper to the correct environment's getNativeElement (WebDriverHarnessEnvironment or TestbedHarnessElement equivalents)."],"exampleFix":"// before\nconst finder = ProtractorHarnessEnvironment.getNativeElement(el);\n// after\nif (el instanceof ProtractorElement) {\n  const finder = ProtractorHarnessEnvironment.getNativeElement(el);\n}","handlingStrategy":"type-guard","validationCode":"import {ProtractorElement} from '@angular/cdk/testing/protractor';\nif (!(el instanceof ProtractorElement)) throw new TypeError('el must come from ProtractorHarnessEnvironment');","typeGuard":"const isProtractorElement = (el: TestElement): el is ProtractorElement => el instanceof ProtractorElement;","tryCatchPattern":"let finder: ElementFinder | undefined;\ntry { finder = ProtractorHarnessEnvironment.getNativeElement(el); } catch { finder = undefined; }","preventionTips":["Only pass TestElements obtained from Protractor-based harnesses to this API","Keep environment-specific unwrap helpers separated in test utilities","Check instanceof before unwrapping shared TestElements"],"tags":["angular-cdk","testing","protractor","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"}