小编Mos*_*rge的帖子

使用 NightWatchJS 迭代元素

我如何在夜间值班中单击元素命令返回的按钮

client.elements('xpath', ".//a[@class='abcd')]", function (allButtons){
        console.log('Element value is '+element)
        allButtons.value.forEach(function (element) {
            this.elementIdClick(element, function(res){});
    }
}
Run Code Online (Sandbox Code Playgroud)

在运行时我收到一个错误

元素值为 [object Object]

TypeError: Object #<Object> has no method 'elementIdClick'
Run Code Online (Sandbox Code Playgroud)

那么我如何从返回的元素列表中获取每个元素 client.elements

我意识到 elementIdClick 的参数是错误的,我将代码更新为

client.elements('xpath', ".//a[@class='abcd')]", function (allButtons){

allButtons.value.forEach(function (element) {
    console.log('Element value is '+element)
    this.elementIdClick(this.elementIdAttribute(allButtons.value[element].ELEMENT, 'id'), function(res){});
Run Code Online (Sandbox Code Playgroud)

现在的错误是

Element value is [object Object]
    TypeError: Cannot read property 'ELEMENT' of undefined
Run Code Online (Sandbox Code Playgroud)

所以再次回到原来的问题。我如何使用 nightwatchJS 从网络元素列表中获取单个元素

automation nightwatch.js

5
推荐指数
1
解决办法
1万
查看次数

在if-statment中对数组使用indexOf的结果不一致

我正在学习节点.下面的代码给出了不一致的结果,即,如果我给出argv1.indexOf('test'),那么代码无法找到文本,但是,有时候它返回true.为什么会如此.

function process(argv1) {
    if(argv1.indexOf('test')) {
        console.log('Text is available in array.');
    }
}
process(['test','one','help', 'one', 'two']);
Run Code Online (Sandbox Code Playgroud)

javascript arrays indexof node.js

0
推荐指数
1
解决办法
78
查看次数