javascript - Getting Json element value from the Element ID -
have question while learning javascript , javascript fm. understand how possible access to
{ element: 1 }, { element: 2},...
because inside detailed information array.
and next step, need make json format executes like
[{name: "myname", surname: "mysurname"}, {name: "myname", surname: "mysurname"}]
and need of the
{ element:1}, {element:2}, ....
i'm using nightwatch.js , code right looks :
.elements('css selector', 'ul li', function(res){ console.log(res.value) console.log(res.value[1].element) browser.elementidattribute(res.value[1].element, 'li', function(newres) { console.log(newres.value) }) })
this executes
[ { element: '1' }, { element: '2' }, { element: '3' }, { element: '4' } ] 2 null
here html:
<html> <meta charset="utf-8"> <body> <ul class="random"> <li class="list"> <div class="name">nick</div> <div class="surname">kyrgios</div> <div class="age">22</div> <div class="city">london</div> </li> <li class="list odd"> <div class="name">nick</div> <div class="surname">kyrgios</div> <div class="age">22</div> <div class="city">london</div> </li> <li class="list"> <div class="name">nick</div> <div class="surname">kyrgios</div> <div class="age">22</div> <div class="city">london</div> </li> <li class="list odd"> <div class="name">nick</div> <div class="surname">kyrgios</div> <div class="age">22</div> <div class="city">london</div> </li> </ul> </body> </html>
here link documentation (if needed) http://nightwatchjs.org/api#elementidvalue
what want achieve not possible.
you null
because you're using wrong command. can see here, used set values elements. https://github.com/nightwatchjs/nightwatch/blob/master/lib/api/element-commands.js#l293
what want use .elementidtext
like:
module.exports = { 'test' : function(browser) { function iterate(elements) { elements.value.foreach(function(el) { browser.elementidtext(el.element, function(r) { console.log(r.value); }); }); } browser .url('http://simsonivini.lv/nightwatch.php') .waitforelementvisible('body', 8000) .elements('css selector', 'ul li div', iterate) .end(); } };
Comments
Post a Comment