问题
I want to iterate over element and do some thing on all of them, e.g. set values etc. For now i have following code, but i cant even get attribute from selected elements.
client.elements("freeforms-widget").then(function (elems) {
for (let elem of elems.value) {
let k = client.elementIdAttribute(elem.ELEMENT,'name');
console.log(k);
}
})
And all i see is following :
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
{ state: 'pending' }
The elems itself seems to be fine
{ state: 'success',
sessionId: 'dd301839-369a-45a2-a38c-4bb8ce0a439b',
hCode: 1204992695,
value:
[ { ELEMENT: '0' },
{ ELEMENT: '1' },
{ ELEMENT: '2' },
{ ELEMENT: '3' },
{ ELEMENT: '4' },
....
What i'm doing wrong and how to fix it?
回答1:
elementIdAttribute()
returns a promise - { state: 'pending' }
is a string representation of a non-resolved pending promise. To have a real value printed on the console you need to resolve the promise:
client.elementIdAttribute(elem.ELEMENT,'name').then(function (k) {
console.log(k);
});
来源:https://stackoverflow.com/questions/38663066/webdriver-io-elements-usage