Closed TK95 closed 8 years ago
jQuery must be included in the page you are testing, see e.g. this file: https://github.com/maxgalbu/nightwatch-custom-commands-assertions/blob/master/tests/html/jqueryElement.html
Thank you, it solved my error. But I still don't have jQuery element. Here is output from console.log :
{ ELEMENT: '2' }
Sometimes I get { ELEMENT: '0' }. Are any ideas?
I guess selenium can't return a reference to the element, because you are outside the DOM where it lives. The nightwatch .element
function does the same:
.element("css selector", "#div", function(el) {
console.log(el);
})
..returns:
{ state: 'success',
sessionId: '4704636e-6737-4945-9885-9cb0619ff054',
hCode: 1370763489,
value: { ELEMENT: '0' },
class: 'org.openqa.selenium.remote.Response',
status: 0 }
Okay. Maybe you know how to fix it? I would be very grateful to you.
What would you like to obtain from the element? There are a lot of selenium functions to get whatever you want, without actually having the element.
I would like to obtain element attributes, innerHTML and array of child nodes. Is it possible?
These are the functions you are looking for:
http://nightwatchjs.org/api#getText http://nightwatchjs.org/api#getAttribute
If you need to assert a value:
http://nightwatchjs.org/api#assert-containsText http://nightwatchjs.org/api#assert-attributeEquals
Obtaining the child nodes won't be useful, same as obtaining the element itself
Okay. Issue can be closed
Here is my code:
After launch It breaks my test, and giving an error :
Obviously, jQuery wasn't found. How can I require jQuery? Or maybe I something missing?