我想学习 webdriverio。 我尝试运行这段代码:
client.init().
url('https://www.example.com').
elements('p').then((result) => {
for (i = 0; i < result.value.length; i++) {
(client.elementIdText(result.value[i])).
then((re) => console.log(re))
}
})
但是没有记录任何内容。
我知道我可以使用 getText('p') 来做到这一点,但只是想知道如何使用 elements('p') 来做到这一点。
最佳答案
希望这个提示能帮助您找到答案:
let totalElements = $$('p').map((result) => {
return result.getText();
});
console.log(totalElements);
或者这个选项
$$('p').forEach(function(result){
console.log(result.getText());
});
备注:$$ Link
要从您的代码中完成它,请执行相同的操作 $$
, 删除 .value
并将方法更改为 getText()
.由于没有任何返回,因为 elementIdText()
将只采用选择器 ID
作为论据。和 <p>
不是身份证。在这里引用 elmentIdText()
for(i=0; i<result.length; i++){
(client.getText(result[i])).
then((re) => console.log(re))
}
关于javascript - WebdriverIO : How to correctly iterate throus elements and log out the getText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45388093/