I want to learn webdriverio. I try to run this code:
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))
}
})
but that logs out nothing.
I know i can do it using getText('p'), but just wanna know how to do it using elements('p').
Hope this hint will help you in finding your answer:
let totalElements = $$('p').map((result) => {
return result.getText();
});
console.log(totalElements);
Or this option
$$('p').forEach(function(result){
console.log(result.getText());
});
Note: $$ Link
And to get it done from your code please do the same $$
, remove .value
and change the method to getText()
. As there is nothing returned because elementIdText()
will take only selector ID
as an argument. And <p>
is not an ID. Refer here for elmentIdText()
for(i=0; i<result.length; i++){
(client.getText(result[i])).
then((re) => console.log(re))
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.