casperjs

CasperJS click event having AJAX call

这一生的挚爱 提交于 2019-11-27 03:40:58
问题 I am trying to fetch data from a site by simulating events using CasperJS with phantomJS 1.7.0. I am able to simulate normal click events and select events. But my code fails in following scenario: When I click on button / anchor etc on remote page, the click on remote page initiates an AJAX call / JS call(depending on how that page is implemented by programmer.). In case of JS call, my code works and I get changed data. But for clicks where is AJAX call is initiated, I do not get updated

How to follow all links in CasperJS?

本秂侑毒 提交于 2019-11-27 03:35:16
问题 I'm having trouble clicking all JavaScript based links in a DOM and saving the output. The links have the form <a id="html" href="javascript:void(0);" onclick="goToHtml();">HTML</a> the following code works great: var casper = require('casper').create(); var fs = require('fs'); var firstUrl = 'http://www.testurl.com/test.html'; var css_selector = '#jan_html'; casper.start(firstUrl); casper.thenClick(css_selector, function(){ console.log("whoop"); }); casper.waitFor(function check() { return

How to save the current webpage with casperjs/phantomjs?

£可爱£侵袭症+ 提交于 2019-11-27 02:57:14
问题 Is there a way to save the current webpage by using casperjs or phantomjs? I tried to get the html and save it into a file. But the resulting file was a lot different from the screenshot of that time (with casper.capture ). Is there a way to save the current webpage? 回答1: Andrey Borisko suggested to use the disk cache to retrieve the resources. My solution is not that efficient, but you don't need to decompress text files. I use XMLHttpRequest to retrieve all resources after I registered them

How to open a new tab in CasperJS

a 夏天 提交于 2019-11-27 02:01:43
I am using CasperJS testing framework to make some test suite since almost a month now, but I am facing a problem in one of them. Here is what I want to do: I am browsing a url (page1) and I have to make another action from an another url (simulate a new tab like we have on our graphics browser) without quitting the first one (page1). The action from the second url is going to change my first one. Hope it's clear enough :) So for now when I reach the step to observe that on my first url I open the second one by doing a thenOpen() , so it's making a new navigation step and I am losing the

What must be wrapped in then() statements in CasperJS? How to determine execution order of sync/async functions?

坚强是说给别人听的谎言 提交于 2019-11-27 00:47:11
I'm having something of a hard time determining what is asynchronous and what is not while running CasperJS, what must be wrapped in then() statements, and what is going to be evaluated when. I'll run into a problem somewhere that has to do with a fall-through break statement, variable scope, or the evaluate() statement, and I'll start wrapping all my code in then() statements... which turns out to not be the problem. I notice that my code runs on two levels when I step through it, an evaluation level that parses the code, and then come the then() statements. Also, my print statements appear

how to persist cookies between different casperjs processes

陌路散爱 提交于 2019-11-26 23:59:32
问题 this is a question about how to persist cookies from one casperjs page to another.. so basically i got a nodejs file that spawns casperjs as a worker to do certain tasks.. one is to login, once logged in I store the cookie in a file. when i spawn the next casper worker.. i want it to to use the cookie rather having to login again.. both these methods failed : first: when i spawn the worker capserjs I add the --cookies-file=./cookiefilename ie var child = spawn('casperjs',['scrape.js','-

CasperJS skip step on timeout

独自空忆成欢 提交于 2019-11-26 23:26:17
问题 I have one page in my casperjs test that has images , I dont what to wait until this page loaded to go to the next step. How can I do it ? I have tryed this way var casper = require("casper").create({ onStepTimeout: function() { this.echo("TIMEOUT" + this.requestUrl,"RED_BAR"); // Some skip page controlling code }, ); var timeout = ~~casper.cli.get(0); casper.start("http://127.0.0.1/index2.php", function () { this.echo("FIRST GOOD PAGE", "GREEN_BAR"); casper.options.stepTimeout = timeout; });

CasperJS - How to open up all links in an array of links

安稳与你 提交于 2019-11-26 23:06:12
问题 I'm trying to make it so that CasperJS will open up every link in an array of links. I have it so that after I open a link, it will display the title of that page. Yet when I run it, nothing is displayed. I can use a for loop to display the links and it works perfectly. This is the code for what I just explained: var x; casper.start(URL, function() { x = links.split(" "); // now x is an array of links for (var i = 0; j < x.length; i++) // for every link... { casper.thenOpen(partialURL + x[i],

casperjs download file without specifying url

烂漫一生 提交于 2019-11-26 22:25:46
问题 Is there any way to download CSV file with casperjs without specifying download URL? I am trying to download CSV file whose URL is dynamically generated when I click the download button. So, I may not be able to use download() well under the situation. 回答1: For the record, it's already possible using 'resource.received' event. If you receive header like this one: Content-Disposition: Attachment; Filename="ExportData.csv" The file generated can be downloaded using following event listener:

CasperJS passing data back to PHP

跟風遠走 提交于 2019-11-26 22:04:57
CasperJS is being called by PHP using an exec() command. After CasperJS does its work such as retrieving parts of a webpage, how can the retrieved data be returned back to PHP? You can redirect output from stdout to an array. On this page it says you can do: string exec ( string $command [, array &$output [, int &$return_var ]] ) It goes on to say: If the output argument is present, then the specified array will be filled with every line of output from the command. So basically you can do exec('casperjs command here, $array_here); Hemerson Varela I think the best way to transfer data from