无法在WCT中访问卷影根内部的元素

时间:2019-01-21 10:36:55

标签: polymer shadow-dom polymer-3.x web-component-tester wct

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

public static class SqlExtensions // needs to be in a static class
{
    public static void AddWithValueAndNullCheck(this SqlParameterCollection collection, string parameterName, object value)
    {
        if (object == null)
        {
            collection.AddWithValue(parameterName, DBNull.Value);
        }
        else
        {
            collection.AddWithValue(parameterName, value);
        }
    }
}

我在imgElement中为空。如何获得img元素? 我也尝试过

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

enter image description here

2 个答案:

答案 0 :(得分:0)

如果您尝试访问影子根目录中的dom元素。尝试;

 this.$.<element-id>

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

答案 1 :(得分:0)

您必须先使用setup函数

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

相关问题