While delving into JavaScript and the JavaScript framework, I have another query. I am seeking clarity on how to access:
{ Element: 1 }, { Element: 2},...
This contains detailed information about the array.
Furthermore, I aim to format it as JSON like so:
[{name: "MyName", surname: "mySurname"}, {name: "MyName", surname: "mySurname"}]
and so forth, to achieve this for any:
{ Element:1}, {Element:2}, ....
I am utilizing nightwatch.js and my current code appears as follows :
.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 results in
[ { ELEMENT: '1' },
{ ELEMENT: '2' },
{ ELEMENT: '3' },
{ ELEMENT: '4' } ]
2
null
Attached is the 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>
For reference, here is a link to the documentation