How to use fillSelectors in casperjs

泪湿孤枕 提交于 2019-12-25 05:48:13

问题


I need to get some content from the page, but if I use fillSelectors() the content is not load. Maybe i need use evaluate(), but i dont undestend where and how.

var casper = require('casper').create()
casper.start('http://console.matomycontentnetwork.com/', function() {
  this.fillSelectors('form#login-form', {
      'input[name="username"]':    'jpost',
      'input[name="password"]':    'matomy123'
  }, true);
  this.clickLabel("Sign In", 'button');
});

casper.then(function() {
  var start_date = '09/01/2015';
  var end_date = '10/07/2015';
  this.evaluate(function() {
    $('#report-range').val('custom').change();
  });

  this.fillSelectors('form#report-form', {          
    'input[name="report[start_date]"]': start_date,
    'input[name="report[end_date]"]':  end_date,
    'input[id="grouping-option-3"]' : true,
    'input[id="grouping-option-2"]' : true,
    'input[id="grouping-option-4"]' : true
  }, true);

  this.click("#run-report");
  this.wait(10000, function () {
    this.echo('.geo_country_name.innerText: ' + this.evaluate(function() {
      return document.querySelector('.geo_country_name').innerText;
    }));
    this.echo('td.alignright:nth-child(5).innerText: ' + this.evaluate(function() {
      return document.querySelector('td.alignright:nth-child(5)').innerText;
    }));
  });
});

casper.run();

Can you help with that?


回答1:


Here are some guesses:

If you want to click on some button to submit a form, don't automatically submit a form. Remove the last argument:

this.fillSelectors('form#report-form', {          
    'input[name="report[start_date]"]': start_date,
    'input[name="report[end_date]"]':  end_date,
    'input[id="grouping-option-3"]' : true,
    'input[id="grouping-option-2"]' : true,
    'input[id="grouping-option-4"]' : true
});

PhantomJS doesn't support element.innerText. You need to use element.textContent.



来源:https://stackoverflow.com/questions/33033639/how-to-use-fillselectors-in-casperjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!