如何在Casperjs中使用fillSelectors [英] How to use fillSelectors in casperjs

查看:157
本文介绍了如何在Casperjs中使用fillSelectors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从页面中获取一些内容,但是如果使用fillSelectors(),则不会加载该内容.也许我需要使用evaluate(),但是我并不想在哪里以及如何使用.

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

您能帮上忙吗?

推荐答案

以下是一些猜测:

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

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

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

这篇关于如何在Casperjs中使用fillSelectors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆