繁体   English   中英

如何在Casperjs中使用fillSelectors

[英]How to use fillSelectors in casperjs

我需要从页面中获取一些内容,但是如果我使用fillSelectors() ,则不会加载该内容。 也许我需要使用validate evaluate() ,但是我并不需要任何地方和方式。

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();

你能帮忙吗?

以下是一些猜测:

如果要单击某个按钮来提交表单,请不要自动提交表单。 删除最后一个参数:

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不支持element.innerText 您需要使用element.textContent

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM