travist / jquery.go.js

An easy-to-use web testing and automation tool that uses the jQuery interface within Node.js to interact with the Phantom.js browser.
MIT License
150 stars 35 forks source link

find() and children() #12

Open iamajoe opened 10 years ago

iamajoe commented 10 years ago

Tried to use these two Sizzle methods and didn't work.

Sometimes you don't want to give an absolute path to the element. For example, if you have a list and you want to iterate through all the items and retrieve one value from a specific div inside of each one.

The code i'm using:

$.getPage(function (page) {
    // Iterate over each 'h2 a' elements.
    $('.ti').each(function (index, element, done) {
        this.children('a', function () {
            // this should now be te 'a' inside '.ti'
            done();
        });
    },
    // This method is called after all the items have been iterated over...
    function () {
        $.close();
    });
});
travist commented 10 years ago

This would probably need to be done manually since 'children' is an iterating function and to create an iterating function outside of a synchronous workflow is difficult (since you have to worry about asynchronous behavior). It may need to be done the same as the each function. https://github.com/travist/jquery.go.js/blob/master/lib/jquery.go.js#L258