D.P
D.P

Reputation: 65

Unable to access elements inside Shadow Root in WCT

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

Upvotes: 1

Views: 341

Answers (2)

Bolu Oluwalade
Bolu Oluwalade

Reputation: 51

you have to use the setup function first

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

Upvotes: 0

Cappittall
Cappittall

Reputation: 3441

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')

Upvotes: 0

Related Questions