Webdriver.io elements usage

谁说胖子不能爱 提交于 2019-12-08 01:04:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!