jquery.go.js icon indicating copy to clipboard operation
jquery.go.js copied to clipboard

Navigating multiple page and capture div text

Open d3ric3 opened this issue 10 years ago • 1 comments

Hi Travis,

Thanks for the great initiative for this library. However, I am struggle using it for some automation. My scenario will be visit each link appear on a page. Upon successfully page load, click on a div and read the text in div.

This is my code. Appreciate if you can give me some guide.

var $ = require('jquerygo');

// Add some default configs.
$.config.addJQuery = false;
$.variables = {};
$.variables.urls = [];
$.variables.name = [];

// visit the web site
$.visit('http://mysite.com', function(){

    $.waitForPage(function() {

    // Iterate through each span.field-content.
    $('div .list_title > a').each(function(index, element, done) {

      // Get the text of this element.
      element.attr('href', function(name){
        //console.log(name);
        $.variables.urls.push(name);
        done();
      });

    }, function() {

      // We are done.
      console.log('Done!');
      $.close();

      // This is not working console will display navigating http://mysite.com/1 navigating http://mysite.com/2 navigating http://mysite.com/3 etc
      for(i in $.variables.urls){
        GrabName($.variables.urls[i]);
      }

    });

  });

});

function GrabName(url) {

    $.visit(url, function(){

        $.waitForPage(function(){

            $('div .name').click(function(){

                $('div .name-prefix').text(function(name_prefix){
                    $('div .name').text(function(name){
                        $.variables.name.push(name_prefix + name);
                        $.close();
                    })
                });

            });

        });

    });

}

d3ric3 avatar Jan 14 '15 03:01 d3ric3

You are closing the Phantom browser with $.close(); before you are done using it within GrabName.

travist avatar Jan 14 '15 14:01 travist