casperjs

Upgrading casperjs to use phantomjs 2.0 from 1.9.8

﹥>﹥吖頭↗ 提交于 2019-12-12 00:16:24
问题 I read that people have found ways to get casperjs to work with phantomjs 2.0 but how could I do the upgrade? For example just swapping out phantomjs folder in /usr/.../casperjs/node_modules/phantomjs with a folder for phantomjs2 doesn't seem to do the trick. I've also made the changes in lib/bootstrap.js to handle the warnings from using 2.0. I'm using mocha-casperjs to create my tests. 回答1: If you want to use PhantomJS 2, then you currently need to either install CasperJS from git (which

Casperjs, how to only proceed after receiving response from an ajax call

故事扮演 提交于 2019-12-11 20:25:18
问题 I want casperjs to make an ajax call but wait for the result from my server. This might take up to 3 minutes, but I can tell from looking at the results of running my script, casper.then function times out and just keeps going after exactly 30 seconds. I've tried putting casper.options.waitTimeout = 180000 /* 3 minutes */; in my code, which does work, and I've tried using this block of code, which seems to wait 3 minutes every single time regardless of the result of my api call. I also know

Pass a list of named functions into function in coffeescript

断了今生、忘了曾经 提交于 2019-12-11 20:22:07
问题 In the API Documentation there is a snippet: casper.waitFor(function check() { return this.evaluate(function() { return document.querySelectorAll('ul.your-list li').length > 2; }); }, function then() { this.captureSelector('yoursitelist.png', 'ul.your-list'); }, function timeout() { this.echo("I can't haz my screenshot.").exit(); }); I need this, but in a coffeescript project. I tried to rewrite it into coffeescript but it didn’t work. Even if i let js2coffe do the job, i get some invalid

How to update the URL in “then*” function?

你。 提交于 2019-12-11 20:00:39
问题 I have below code snippet. var admin_url = "http://www.sampledomain.com/"; var casper = require('casper').create(); casper.start(); casper.thenOpen( "http://www.test.com", { method: "post", data: { param1: "some data" } }, function() { what_i_want = this.getPageContent().split("[")[1].split("]")[0] admin_url += what_i_want; } ); casper.thenOpen(admin_url, function() { this.echo(this.getCurrentUrl()); }); casper.run(); I first post to http://www.test.com, then use the returned data, I try to

Use casper function inside casper.evaluate()

落花浮王杯 提交于 2019-12-11 17:09:08
问题 it's possible using casper function inside casper.evaluate() with jquery code inside? I need to iterare elements in a way similar to how jquery does. I'm loading jquery.js lib This is my try script: casper.evaluate(function(){ $('#size-modal .size-panel-title a').each(function(){ $(this).click(); accordionTab = $(this).attr('href'); casper.capture(screenShotOutput + "PDP-" + accordionTab +".png"); }); }); in this page there are 2 accordion and i want a screenshot for each opened accordion. It

Load The Javascript Of The Page While Loading The Page Itself With CasperJs

我们两清 提交于 2019-12-11 15:06:03
问题 I am trying to submit a form. When I am using firefox the page will be loaded then I open the firebug I can see a input field named "content_html" but when I go to check the source of the page from "view page source" I do not see the input field "content_html" . I checked further and found out there is a javascript which will be loaded in the browser to show that input field. The code is like geteditorinit("http://example.com/pub","data[content_html]",298996,1,750,350,0,0,"content_html"); So

How to stop a loop when clicking asynchronously in CasperJS

五迷三道 提交于 2019-12-11 13:16:14
问题 I'm crawling multiple pages using CasperJS, but I got stuck. The maximum number of pages are 200 but I want to stop the execution if the XPath below doesn't exist (for a page before the 200th). How can I set up i variable? var casper = require('casper').create(); var x = require('casper').selectXPath; for (var i=1; i <=200; i++) { casper.wait(6000, function() { casper.thenClick(x('//*[@id="mArticle"]/div[2]/a['+i+']'), function (){ console.log('Searching dic'); words = words.concat(this

Asynchronous Process inside a casperjs script for while loop

ぐ巨炮叔叔 提交于 2019-12-11 12:43:14
问题 I'm using a while loop to open a list of usernames from a csv file. For each username of these, I have to open a URL and dump the page into a file. However, then casper.thenOpen always runs only one time. I understood from Asynchronous Process inside a javascript for loop that this is due to that it is an asynchronous process. I need to do the same for my code below: casper.then(function(){ stream = fs.open('usernames.csv', 'r'); targetusername = stream.readLine(); i = 0; while(targetusername

SocketIO + PhantomJS emit not working

岁酱吖の 提交于 2019-12-11 12:12:16
问题 I am having a pretty specific problem but I hope people can point me in the right direction for how to debug or even fix it. I am trying to write a local client which can run and test a webpage I had built which uses SocketIO. I am running Phantom with the command line option --web-security=false since otherwise no in or out connections are legal as my local tester is not considered part of the same origin as my website I am testing (had to fix that before the listening would work). Using

CasperJS inject javascript via this.evaluate

[亡魂溺海] 提交于 2019-12-11 11:33:20
问题 Today I tried to inject some javascript logic into remote page using CasperJS with PhantomJS together. Well, I'm quite surprised because of that: casper.then(function() { console.log(this.evaluate(function() { function myMethod() { return 'Any thing?!'; } return myMethod(); })); console.log(this.evaluate(function() { return myMethod(); })); }); I tried many combinations... Like: casper.evaluate(...) this.evaluate(...) casper.page.evaluate(...) <- directly to phantomJS this.page.evaluate(...)