The index starts at 0. .nativeElement () APIAPIDOM. // BannerComponent test instance h1 = fixture. innerText). Since its inception through to its most recent release, Angular 15, Angular has been designed with testability in mind. It should be avoided while working with angular because angular has its own ChangeDetection which requires it to be worked with fixtures. Permitting direct access to the DOM can make your application more vulnerable to XSS attacks. 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.. How to Create Custom Directive in Angular? domAugulardom, div div , div "ElementRef " Angular native native DOM my-app querySelector API div , null this.elementRef.nativeElement my-app angular, ngAfterViewInit templatedom. Like this: var myElement = angular.element ( document.querySelector ( '#some-id' ) ); As explained above, we wrapped document.querySelector () with the angular.element to get the function to work. Content available under a Creative Commons license. For below element with an id as shan: We can use below ways to get it in unit testing: It is used to get DebugElement for a DOM object. In this first example, the first