我已经在Nightwatch中为我的UI测试创建了此自定义命令。这是在充分:Nightwatch:使用自定义命令遍历所有选择的标签
exports.command = function(element, callback) {
var self = this;
try {
this.waitForElementVisible('body', 15000);
console.log("trying..");
window.addEventListener('load', function() {
var selects = document.getElementsByName("select");
console.log(selects);
}, false);
} catch (err) {
console.log("code failed, here's the problem..");
console.log(err);
}
this
.useXpath()
// click dropdowns
.waitForElementVisible(element, 15000)
.click(element)
.useCss()
.waitForElementVisible('option[value="02To0000000L1Hy"]', 15000)
// operation we want all select boxes to perform
.setValue('option[value="02To0000000L1Hy"]', "02To0000000L1Hy")
.useXpath()
.click(element + '/option[4]');
if (typeof callback === "function") {
callback.call(self);
}
return this; // allows the command to be chained.
};
什么我试图做的是网页加载完毕后,我想检索所有的选择框,并对其执行相同的操作。除try/catch块中的代码外,所有内容都正常工作。我不断收到'[ReferenceError:window is not defined]',我不确定如何通过它。