开发者

Node.js module that inspects DOM elements

I'm using zombie.js, a headless browser mostly for testing purposes. It creates a browser object that once the function visit() is called allows you to play with the DOM of a 开发者_开发知识库given page. However, I wasn't able to get it to that extent. It looks like there is an issue with the parser used in zombie. Here is the error:

User/murf/Documents/workspace/node_code/node_modules/zombie/node_modules/html5/lib/html5/tokenizer.js:62

Has anyone found a similar issue? If so, is there a way to go around it? Or maybe is there is another node module that does similar work? Any idea is greatly appreciated.

Thanks


ZombieJS and other web testing tools is built on JSDOM which is really easy to use just like Zombie. However the thing is you don't have stuff like "type" but you could easily simulate it in JSDOM, example:

var jsdom = require("jsdom");

jsdom.env("http://nodejs.org/dist/", [
  'http://code.jquery.com/jquery-1.5.min.js'
], function(errors, window) {
  console.log("there have been", window.$("a").length, "nodejs releases!");
});

That is a code sample from JSDOM, so if you want for example to simulate type you'll have to trigger for instance keydown manually

$('someInput')
              .val('x')
              .keydown();

That will somehow simulate type('x'), for ex. for google search that will trigger getting the suggestion box.
However in order to properly simulate it, you have to create a keydown event with keyCode and everything.

I'm working on a new headless browser for Node called htmlnode, but its still work in progress, expected to be usable next week, and its built on top of HtmlUnit.

Other options:

  • SodaJS
  • Tobi (headless, built on top of JSDOM)
  • JellyFish
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜