johntitus / node-horseman

Run PhantomJS from Node
MIT License
1.45k stars 124 forks source link

ScrollDown difficult #322

Open marcelinhov2 opened 6 years ago

marcelinhov2 commented 6 years ago

Hey guys, how are you? First of all, congrats for your job, horseman is fucking awesome.

So, I'm trying to navigate at this Google modal without success.

Can someone helps me? I already tried mouseEvents, evaluate... but got no success...

Thanks!

marcelinhov2 commented 6 years ago
horseman
        .open('http://www.google.com')
        .type('input[name="q"]', 'VALERIM CENTER')
        .keyboardEvent('keypress',16777221)
        .wait( 5000 )
        .screenshot('test.png')
        .click('[data-reply_source="local-search-reviews-list"]')
        .wait( 5000 )
        .screenshot('test00.png')
        .click("g-dropdown-button")
        .evaluate(function(){
          document.querySelector('g-dropdown-button').click();
        })
        .wait( 500 )
        .screenshot('test0.png')
        .click("g-menu-item:contains('Most recent')")
        .wait( 5000 )
        .screenshot('test1.png')
        .click('.review-dialog-list')
        // .mouseEvent('mousedown', 0, 10000)
        // .evaluate(function(){
        //   return document.querySelector('.review-dialog-list');
        // })
        // .then( function( reviewsList ) {
        //   console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
        //   console.log( reviewsList )
        //   // reviewsList.style.height = '200px';
        //   console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
        // } )
        .html('.review-dialog-body')
        .evaluate(function(){
          return document.querySelector('.review-dialog-list').scrollTo(0, document.querySelector('.review-dialog-list').scrollHeight);
        })
        .wait( 2000 )
        .screenshot('test2.png')
    });

My tries until now...

marcelinhov2 commented 6 years ago
FATAL
{ event: 'fatal',
  message: '{"line":2,"message":"undefined is not a constructor (evaluating \'document.querySelector(\'.review-dialog-list\').scrollTo(0, document.querySelector(\'.review-dialog-list\').scrollHeight)\')","stack":"fn\\nevaluate\\n\\nglobal code\\nevaluateJavaScript@[native code]\\nevaluate@phantomjs://platform/webpage.js:390:39\\nphantomjs://code/bridge.js:122:61    at Horseman.<anonymous> (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/node-horseman/lib/actions.js:839:38)\\n    at Horseman.tryCatcher (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/util.js:16:23)\\n    at Promise._settlePromiseFromHandler (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:512:31)\\n    at Promise._settlePromise (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:569:18)\\n    at Promise._settlePromiseCtx (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:606:10)\\n    at Async._drainQueue (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:138:12)\\n    at Async._drainQueues (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:143:10)\\n    at Immediate.Async.drainQueues (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:17:14)\\n    at runCallback (timers.js:637:20)\\n    at tryOnImmediate (timers.js:610:5)\\n    at processImmediate [as _immediateCallback] (timers.js:582:5)","name":"Error"}' }
{ line: 2,
  message: 'undefined is not a constructor (evaluating \'document.querySelector(\'.review-dialog-list\').scrollTo(0, document.querySelector(\'.review-dialog-list\').scrollHeight)\')',
  stack: 'fn\nevaluate\n\nglobal code\nevaluateJavaScript@[native code]\nevaluate@phantomjs://platform/webpage.js:390:39\nphantomjs://code/bridge.js:122:61    at Horseman.<anonymous> (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/node-horseman/lib/actions.js:839:38)\n    at Horseman.tryCatcher (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:512:31)\n    at Promise._settlePromise (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:569:18)\n    at Promise._settlePromiseCtx (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/promise.js:606:10)\n    at Async._drainQueue (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:138:12)\n    at Async._drainQueues (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:143:10)\n    at Immediate.Async.drainQueues (/Users/marcelinhov2/Workspace/reviewr/crawlers/google/node_modules/bluebird/js/release/async.js:17:14)\n    at runCallback (timers.js:637:20)\n    at tryOnImmediate (timers.js:610:5)\n    at processImmediate [as _immediateCallback] (timers.js:582:5)',
  name: 'Error',
  toString: [Function] }
ajhalls commented 6 years ago

Did you make any progress on this? I was trying the same thing.