Unable to access elements inside Shadow Root in WCT

340 Views Asked by At

In my unit test, I am unable to access dom element from shadow root.

var el = fixture('basic');
var imgElement = el.shadowRoot.querySelector('img');

I am getting null in imgElement. How to get the img element? I have tried also,

var imgElement2= document.querySelector('img');

enter image description here

2

There are 2 best solutions below

0
On

If you are trying to access the dom element in the shadow root. Try ;

 this.$.<element-id>

or

this.shadowRoot.querySelector(selector)  / ie:('#element-id')
0
On

you have to use the setup function first

   suite('test', function(){
                setup(function () {
                my-el = fixture('DefaultElement');
            });