量角器:addLocator():'无法读取 属性 'querySelectorAll of null''

Protractor: addLocator() : 'Cannot read property 'querySelectorAll of null' '

我试图 运行 来自 Protractor 文档 ( http://angular.github.io/protractor/#/api?view=ProtractorBy.prototype.addLocator ) 的标准示例。并出现错误:'无法读取 属性 'querySelectorAll of null'

    by.addLocator('buttonTextSimple',
    function(buttonText, opt_parentElement, opt_rootSelector  ) {
    var using = opt_parentElement,
        buttons = using.querySelectorAll('button');
    return Array.prototype.filter.call(buttons, function(button) {
        return button.textContent === buttonText;
        });
    });

观点相同:

<button ng-click="doAddition()">Go!</button>

我应该怎么做才能解决这个问题?

您应该像这样声明一个名为 using 的变量:

var using = opt_parentElement || document;

因此,如果没有提供可选的父元素,则将使用全局 document 来查询结果。

不确定它是否是文档中的拼写错误,或者 Protractor 在未设置的情况下应该使用一些默认值自动填充 opt_parentElement 变量。