ElementRef is usually combined with ViewChild and AfterViewInit to access child DOM elements from an Angular directive. You can read more about headless chrome in here https://developers.google.com/web/updates/2017/04/headless-chrome#tldr. Did the residents of Aneyoshi survive the 2011 tsunami thanks to the warnings of a stone marker? import { Component, OnInit, ElementRef } from '@angular/core'; @Component({ I tried the code below but didn't work. You can't access class by doing something like. let buttonElement = fixture.debugElement.nativeElement.querySelector('.set-button'); buttonElement.click(); Find the test function. @ViewChildren {read: ElementRef} ElementRef. Powered by Discourse, best viewed with JavaScript enabled, How to trigger a click event on child element got as result when using querySelector on native element in angular2/angular4. div "ElementRef " Angular native native DOM my-app querySelector API div At least I hope you do! nativeElement returns a reference to the DOM element which can also come under debugElement as stated above.You can use it do actions such as click () event in test cases.. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. In this post, we've seen what ElementRef is and how it can be used with other APIs to access the native DOM elements with simple Angular 10 examples. ngAfterViewInit () . const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('h1').textContent).toContain('Welcome to angular-unit-test!'); })); let's test our Angular example application. Thrown if the specified selectors are invalid. If we change the value of component property at runtime, then we need to call detectChanges () again to observe the new value. interface returns the first element that is a descendant of the element on which it is Get the first
element in with class="example": Change the text of the element with id="demo": Select the first
element with the parent is a