首页 > 解决方案 > 无法访问 WCT 中 Shadow Root 内的元素

问题描述

在我的单元测试中,我无法从影子根访问 dom 元素。

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

我在 imgElement 中得到空值。如何获取 img 元素?我也试过,

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

在此处输入图像描述

标签: polymershadow-dompolymer-3.xweb-component-testerwct

解决方案


您必须先使用该setup功能

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


推荐阅读