我正在尝试为浏览器自动测试套件和能够抓取的无头浏览器平台列出可能的解决方案列表.
浏览器测试/清除:
JAVASCRIPT
Node.js的
我正在使用CasperJS通过网站自动执行一系列点击,完成表单,解析数据等.
Casper似乎被组织成一个then语句形式的预设步骤列表(参见他们的例子:http://casperjs.org/quickstart.html)但是不清楚是什么触发了实际运行的下一个语句.
例如,是否then等待所有待处理的请求完成?是否被injectJS视为待处理请求?如果我有一个then嵌套的语句 - 链接到open语句的末尾会发生什么?
casper.thenOpen('http://example.com/list', function(){
casper.page.injectJs('/libs/jquery.js');
casper.evaluate(function(){
var id = jQuery("span:contains('"+itemName+"')").closest("tr").find("input:first").val();
casper.open("http://example.com/show/"+id); //what if 'then' was added here?
});
});
casper.then(function(){
//parse the 'show' page
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找CasperJS中流程如何工作的技术解释.我的具体问题是我的上一个then陈述(上图)在我的casper.open陈述之前运行而我不知道为什么.
我已经为我的Ruby代码编写了一段时间的测试,但作为一个前端开发人员,我显然很有兴趣将它带入我为前端代码编写的代码中.我一直在玩的有很多不同的选择:
人们用于测试的是什么?还有人们测试的是什么?只是JavaScript?链接?形式?硬编码的内容?
任何想法将不胜感激.
如何在文件系统中创建文件并将其内容this.getPageContent()放入其中?
我知道CasperJS网站上有一篇关于如何在Windows上安装CasperJS的文档,但请注意这些人只是为专业人士解释的.
如果你是所有这些CasperJS和PhantomJS世界的新手,你就没有机会理解甚至花两天时间试图搜索网络以获得更好的解释.
我正在开发一个项目,需要我项目网站上列出的每个网站的屏幕截图,环顾四周我发现PhantomJS对于这个任务非常棒(网站截图).
我下载了PhantomJS并粘贴了我用来发送命令时运行良好的phantomjs.exe文件.system32cmd.exe
我甚至设法抓住phantomjs.exe唯一的屏幕截图.但是当我注意到这两个工作(CasperJS和PhantomJS)时工作量可能会更容易,因为我甚至能够在使用CasperJS时减小屏幕截图的大小,我的问题就来了.
事实上,我想要CasperJS的唯一用途是限制镜头大小但是从昨天开始我一直试图弄清楚如何让CasperJS在Windows上运行但却无济于事.
我已经下载了CasperJS并试图以多种方式安装它,也试图按照文档但没有任何东西.
我将CasperJS文件夹名称从其下载名称更改为CasperJS,如文档所示,但是当我检查cmd尝试调用某些命令时,没有任何反应.
无论如何要剪切故事镜头可以任何人帮我简单地考虑到我是一个新手来解释如何在窗口上安装CasperJS或者如果可能的话只用PhantomJS我怎么能重新调整程序产生的大小让我说如果我想要一个960到400px.
如何通过提交表格登录CasperJS.我搜索谷歌并没有找到任何关于它的好例子.
我正在尝试在我的Mac(Yosemite)上安装PhantomJS.
我做了以下事情:
npm install phantomjs
Run Code Online (Sandbox Code Playgroud)
然后我做了:
npm install phantomjs-prebuilt
Run Code Online (Sandbox Code Playgroud)
这两个都出现在我的node_modules中.但是当我试着奔跑时,phantomjs --version我得到了
-bash: phantomjs: command not found
Run Code Online (Sandbox Code Playgroud)
还尝试从下载网站安装二进制文件,但没有.我错过了什么?最终目标是使用casperjs,但目前casper正在询问
Fatal: [Errno 2] No such file or directory; did you install phantomjs?
Run Code Online (Sandbox Code Playgroud)
我以为我做了......?
我有一个带iframe的网页.我想使用CasperJS访问iframe的内容.特别是,我需要单击按钮并填写表单.我怎样才能做到这一点?
主要网页是 main.html:
<html><body>
<a id='main-a' href="javascript:console.log('pressed main-a');">main-a</a>
<iframe src="iframe.html"></iframe>
<a id='main-b' href="javascript:console.log('pressed main-b');">main-b</a>
</body></html>
Run Code Online (Sandbox Code Playgroud)
iframe是:
<html><body>
<a id='iframe-c' href="javascript:console.log('pressed iframe-c');">iframe-c</a>
</body></html>
Run Code Online (Sandbox Code Playgroud)
我天真的做法:
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
casper.start("http://jim.sh/~jim/tmp/casper/main.html", function() {
this.click('a#main-a');
this.click('a#main-b');
this.click('a#iframe-c');
});
casper.run(function() {
this.exit();
});
Run Code Online (Sandbox Code Playgroud)
当然,这不起作用,因为a#iframe-c选择器在主框架中无效:
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://jim.sh/~jim/tmp/casper/main.html, HTTP GET
[debug] [phantom] Navigation requested: url=http://jim.sh/~jim/tmp/casper/main.html, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://jim.sh/~jim/tmp/casper/main.html"
[debug] …Run Code Online (Sandbox Code Playgroud) 为什么当我使用console.log的evaluate,它的工作原理:
casper.then(function() {
this.evaluate( function() {
console.log('hello');
});
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
casper.then(function() {
this.evaluate( function() {
setTimeout( function() {console.log('hello');}, 1000);
});
});
Run Code Online (Sandbox Code Playgroud) 我在用waitFor().代码如下:
casper.waitFor(function check() {
return this.evaluate(function() {
return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
});
}, function then() {
console.log('Done');
});
Run Code Online (Sandbox Code Playgroud)
我把它作为控制台输出
Wait timeout of 5000ms expired, exiting.
Run Code Online (Sandbox Code Playgroud)
如何增加超时?
编辑:我已将代码更改为
casper.waitFor(function check() {
return this.evaluate(function() {
return this.evaluate(someFunction, 'variable 1','variable 2','variable 3') === 'yes';
});
}, function then() {
console.log('Done');
},10000);
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
CasperError: Invalid timeout function, exiting.
C:/filename:1720 in _check
Run Code Online (Sandbox Code Playgroud) casperjs ×10
javascript ×6
phantomjs ×6
frontend ×1
iframe ×1
installation ×1
jasmine ×1
scrapy ×1
selenium ×1
testing ×1
web-scraping ×1
webkit ×1
windows ×1