assaf / zombie

Insanely fast, full-stack, headless browser testing using node.js
http://zombie.js.org/
MIT License
5.66k stars 522 forks source link

query/All selectors are not returning expected results #266

Closed lundin closed 12 years ago

lundin commented 12 years ago

See the EDIT note below about wait and the question.

Hi, Actually i wrote this in one of the closed issues, but i guess it can easily be overlooked.So here it goes:

I am new to Zombie (and nodejs) but I am having problems with the selectors. Looked into the source (and i guess it rely upon JSdom).

browser.html() has the content, it never fails.However html(selector) always returns the entire document no matter the selector.

browser.query or queryAll ('div') =>always returns undefined

browser.document.getElementById('whatever')=>return null

What am i missing ?

The thing (and this is so strange) is that i have "somehow" made it work once, becuase i have a file with all a hrefs in a document by query

zombie.visit("myURL", function (err, browser) { if (err) throw(err.message); console.log (browser.html()); fs.createWriteStream("file", { flags: "a", encoding: "encoding", mode: 0666 }).write(browser.document.querySelectorAll("a[href^=]")); });

however, i dont remember if this was the piece of code i was using becuase i cant replicate it! I have tried everything document.xxxxxx(selector) and nothing returns the correct DOMquery,other than null or undefined.

-EDIT

Ok, so some more testing with various browser params like waitfor and runscripts seems to change what can be fetched. Overall i feel the results of a request can vary and the params needs to be set by experimental methods (from DOM to DOM).

So my question is, can i write some js client function (i have control of the URL being visited) and say to Zombie wait for this function to exceute and return the results of the DOM "as-it is" (i guess the fire command) now rather than some other events.Somehow i would like to make sure operations are running client side and then do some operation on it and communicate the resulting DOM back to zombie.

it's not that i dont trust zombie to return the dom, however all the wait(done) or wait(function) has not yield the desired output on all the test URLs,so i think the best thing is if the client side can assure that the DOM tree is correct, everthying has been excecuted.

So the question is, can i run the client-side script (i am the owner..and make sure it all get executed) and pass something from that function back to zombie that would be very good.

sudoaza commented 12 years ago

Hey there @lundin i've tracked my issue with selectors back to a couple of "document.write" in the html, removing them is all it needs to work. It doesn't even matter what you are writting, document.write('a'); breaks the selector for me. But at least now i know what to look for :P

lundin commented 12 years ago

Hi rata,

Thanks for the feedback. Ok make sense then, will try to find it in my test samples as well. Overall i feel Zombie is genius but in the the end jsdom is no chrome/V8 ;) So i am using Phantomjs for the moment.

Again,thanks for the heads up!

assaf commented 12 years ago

document.write added back in latest release.