标签: casperjs

jQuery":contains()"模拟纯JS

我正在为CasperJS编写一个脚本.我需要单击包含"1"的跨度的链接.在jQuery中可以使用:contains('1'),但是纯Javascript中的选择器的解决方案是什么?

HTML: <a class="swchItem"><span>1</span></a><a class="swchItem"><span>2</span></a>

jQuery变种: $('a .swchItem span:contains("1")')

UPD CasperJS代码:

casper.then(function () {
    this.click('a .swchItem *select span with 1*')
})
Run Code Online (Sandbox Code Playgroud)

html javascript jquery phantomjs casperjs

5
推荐指数
1
解决办法
2204
查看次数

为什么Phantom,Casper和Meteor需要自己的可执行文件?

幻影和Meteor是由Node构建的,而Casper是由Phantom构建的.为什么他们每个人都需要自己独立的可执行文件,而不是require通过Node.js的库?

(我发现这使得它们更难以使用,特别是在Windows上.)

node.js phantomjs casperjs meteor

5
推荐指数
1
解决办法
581
查看次数

捕获和处理CasperError

使用CasperJS如何捕获和处理CasperError?

默认似乎继续执行程序(除了传播错误之外什么都不做).

这些错误记录到控制台/标准输出,但我似乎没有看到(从文档)捕获和处理这些错误的方法.

例:

this.fillSelectors(selector, data);
Run Code Online (Sandbox Code Playgroud)

可能产生:

CasperError:填充表单时遇到错误:找不到表单

我知道在调用之前我可以检查以确保一切都存在,但有没有办法在事后捕获?(这适用于许多其他操作,例如casper.click)

casperjs

5
推荐指数
1
解决办法
5764
查看次数

casperjs 错误:从 node.js 运行时,casper 没有方法 start

运行最简单的 casperjs 示例给我一个错误:

casper.start('http://casperjs.org/', function() {
       ^
TypeError: Object function (req, res) {
    var raw = new Model(data || (allowBody ? req.body : {}));
    raw.save(cb || function (err, obj) {
      if (err) return res.jsonp(500, err);
      res.jsonp(obj);
    });
  } has no method 'start'
    at Object.<anonymous> (/Users/path/to/main.js:16:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3
Run Code Online (Sandbox Code Playgroud)

我正在运行的代码是:

var utils = require('utils');
var casper = require('casper').create();

casper.start('http://casperjs.org/', function() {
    this.echo(this.getTitle());
});

casper.thenOpen('http://phantomjs.org', …
Run Code Online (Sandbox Code Playgroud)

node.js casperjs

5
推荐指数
1
解决办法
2566
查看次数

Casperjs"casper.test属性只能使用`casperjs test`命令"但不能调用casper测试

错误:

casper.test property is only available using the `casperjs test` command
Run Code Online (Sandbox Code Playgroud)

搜索了我的整个代码库"casper.test","this.test","@ test"等,但没有一个存在.查看casper代码,需要触发其中一个以引发此错误.

该错误是间歇性的,仅在某些casper运行时发生.有没有其他人得到这个错误?我跑1.1.0-beta3.

phantomjs casperjs

5
推荐指数
2
解决办法
2243
查看次数

Casperjs状态在网页上失败

从Casperjs 访问https://disqus.com/profile/login/链接会继续返回以下内容

[警告] [幻像]加载资源失败,状态=失败:https: //disqus.com/profile/login/

ensnare.js

var casper = require("casper").create({
    verbose: true,
    logLevel: "debug"
});

casper.options.timeout = 15000;

casper.start("https://disqus.com/profile/login/", function() {
    this.echo("YES!", "GREEN_BAR");
    this.echo(this.getTitle());
});

casper.run();
Run Code Online (Sandbox Code Playgroud)

config.json

{"ignoreSslErrors": true, "cookiesFile": "biscuit", "maxDiskCacheSize": 1000, "diskCache": true}
Run Code Online (Sandbox Code Playgroud)

请注意,我将"ignoreSslErrors"更改为false,但它不起作用.

从终端调用脚本

./phantomjs --config=config.json casperjs/bin/bootstrap.js --casper-path=casperjs --cli ensnare.js
Run Code Online (Sandbox Code Playgroud)

截图

在此输入图像描述 我怎么解决这个问题呢?我可以无问题地访问其他页面.

phantomjs casperjs

5
推荐指数
2
解决办法
6300
查看次数

CasperJS:下拉列表;选择一个选项,代码可以在 browser&amp;slimer 中运行,但不能在 phantom 中运行

这是我的问题:我在一个特定的情况下尝试设置选择下拉列表的选项。我通常使用this.mouse.up() + this.mouse.down(),但在这种情况下不能,因为这种行为在带有 webkit 的网站上不起作用(您可以将两者与 google chrome 和 Firefox 进行比较)。

这里是 url:在我的示例中,我想将字段“ANNEE”设置为年份 2008

我的代码:(我的函数更改 HTML 并启动 change() 事件)

//custom function
casper.fillSelect = function(selectSelector, optionText){
    this.evaluate(function(sel,setByText) {
        if ("createEvent" in document) {
            var evt = document.createEvent("HTMLEvents")
                ,x = document.querySelectorAll(sel + ' > option')
                ,l = x.length
                ;
                evt.initEvent("change", false, true);

            for (i=0; i<l; i++){
                if(x[i].textContent.indexOf(setByText) !== -1){
                    console.log(x[i]);
                    console.log(x[i].getAttribute('value'));
                    x[i].setAttribute('selected', true);
                    x[i].parentNode.dispatchEvent(evt);
                }
            }
        }
        else {console.log("error with fillSelect");}
    },selectSelector, optionText);
};

//event
casper.test.on('fail', function(failure) {
    casper.capture('fail.png');
}); …
Run Code Online (Sandbox Code Playgroud)

javascript html-select phantomjs casperjs slimerjs

5
推荐指数
1
解决办法
4851
查看次数

casperjs无法打开文件

这可能是一个简单的问题,但我不能为我的生活弄清楚我做错了什么.我正在尝试使用casperjs来构建一个刮刀.我已经按照教程下载了这里的brew:

http://docs.casperjs.org/en/latest/installation.html
Run Code Online (Sandbox Code Playgroud)

然后我继续在这里找到的快速入门:

http://docs.casperjs.org/en/latest/quickstart.html
Run Code Online (Sandbox Code Playgroud)

我将sample.js文件保存到我的桌面并尝试使用以下命令从终端运行它:

$ casperjs sample.js
Run Code Online (Sandbox Code Playgroud)

但是它总是返回无法打开文件:sample.js.如果我只是在终端上运行$ casperjs所有关于它是什么版本的信息等等,所以似乎正确安装了casperjs.

我还确保安装了必需的先决条件.我意识到这不是一大堆信息,但是有没有人有任何想法?

这是我在终端中得到的错误代码:

Unable to open file: sample.js
Run Code Online (Sandbox Code Playgroud)

第二次编辑:

也许我遇到麻烦的地方是这些先决条件?

Python 2.6 or greater for casperjs in the bin/ directory
Run Code Online (Sandbox Code Playgroud)

我安装了python,但我不确定"bin /目录中的casper"部分.该文档没有说明如何做到这一点.

terminal casperjs

5
推荐指数
1
解决办法
1373
查看次数

在Node.js回调中调用模块函数

我有一个写入日志文件的模块。(对不起,但您明白了!)

require = patchRequire(global.require)
fs = require('fs')

exports.h =

  log: ()->
    for s in arguments
      fs.appendFile "log.txt", "#{s}\n", (e)->
        if (e) then throw e
Run Code Online (Sandbox Code Playgroud)

当我直接调用它时,它可以工作。但是,当我从回调中调用它时,例如casperjs start事件:

h = require('./h').h
casper = require('casper').create()

casper.start "http://google.com", ()->
  h.log("hi")

casper.run()
Run Code Online (Sandbox Code Playgroud)

...我总是得到这个或类似的“未定义的” TyepError:

TypeError: 'undefined' is not a function (evaluating 'fs.appendFile("log.txt", "" + s + "\n", function(e) {
      if (e) {
        throw e;
      }
    })')
Run Code Online (Sandbox Code Playgroud)

谷歌搜索并没有很多线索!

node.js casperjs

5
推荐指数
1
解决办法
1484
查看次数

如何模拟点击谷歌地点自动完成结果?

我正在努力在我的集成测试中与我的 google 地方自动完成结果进行交互。

var placeSelector = '.pac-container .pac-item:first-child';

exports.runTest = function(test) {
    casper.waitForSelector('input.street-address'); // wait for page to load
    casper.sendKeys('input.street-address', 'fake address here', {keepFocus: true});

    casper.waitUntilVisible(placeSelector);

    casper.then(function() {
        casper.click(placeSelector); // THIS DOES NOT DO ANYTHING

        // if its possible to trigger the event in the context of the page, I 
        // could probably do so. However, I've scoured google's docs and cannot find the 
        // event that is fired when a place is clicked upon.
        casper.evaluate(function() {
            //google.maps.places.Autocomplete.event.trigger(???);
        }); 
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript integration-testing google-maps google-places-api casperjs

5
推荐指数
1
解决办法
2475
查看次数