casperjs

JS Testing: Trigger jQuery keypress event from CasperJS and PhanthomJS

偶尔善良 提交于 2019-12-04 20:27:58
my webpage has a listener to the enter key press event. I am trying to run the casperjs code below to trigger this event, but without success. Although no error is prompted out, the (evaluate) function returns true and the code works fine from my chrome console, the function result, that should be sending a request to the server is never happening casper.then(function(){ var result = this.evaluate(function(term){ var search_form_id = "#search-form"; $(search_form_id).val(term); jQuery(search_form_id).trigger(jQuery.Event('keypress', {which: 13, keyCode: 13})); return true; }, 'Techcrunch');

Click all anchor tags on page with given class, but cancel prior to navigation

人走茶凉 提交于 2019-12-04 19:31:38
Trying to automate some testing for some analytics tracking code, and I'm running into issues when I try passing links into the each() method. I copied a lot of this from stackoverflow - how to follow all links in casperjs , but I don't need return the href of the link; I need to return the link itself (so I can click it). I keep getting this error: each() only works with arrays. Am I not returning an array? UPDATE: For each anchor tag that has .myClass, click it, then return requested parameters from casper.options.onResourceReceived e.g. event category, event action, etc. I may or may not

How to use NodeJS / PhantomJS / CasperJS on Windows 7

一个人想着一个人 提交于 2019-12-04 19:26:16
I need to scrape a website form (on-the-fly) which has AJAX and SESSIONS. I did a lot of research and I came across several possible solutions one being Python::Mechanize. I don't know python and cURL alone for PHP (from my understanding) cannot handle AJAX or submit forms. I found what i believe is the possible stack which can lead me to grace :). Problem is that I do not know how to use these packages at all. I downloaded and installed NODEjs and I can call it from cmd. (great) I downloaded and installed PhantomJS (Not sure how to setup the PATH so that it is dynamic so I have to manually cd

phantomjs with nohup not working

柔情痞子 提交于 2019-12-04 18:49:24
I was trying to run phantomjs script via ssh using nohup command . But nohup threw an error which i found in nohup.out file. My command was --> nohup phantomjs example.js & phantomjs example.js run perfectly without nohup . I have also created a bash script to run this command with nohup but both time, I got this error --> events.js:72 throw er; // Unhandled 'error' event ^ Error: EBADF, read ** code of example.js var page = require('webpage').create(), system = require('system'), address, output, size; if (system.args.length < 3 || system.args.length > 5) { console.log('Usage: rasterize.js

Phantomjs equivalent of browser's “Save Page As… Webpage, complete”

血红的双手。 提交于 2019-12-04 17:21:47
For my application I need to programmatically save a copy of a webpage HTML along with the images and resources needed to render it. Browsers have this functionality in their Save page as... Webpage, complete options. It is of course easy to save the rendered HTML of a page using phantomjs or casperjs. However, I have not seen any examples of combining this with downloading the associated images, and doing the needed DOM changes to use the downloaded images. Given that this functionality exists in webkit-based browsers (Chrome, Safari) I'm surprised it isn't in phantomjs -- or perhaps I just

Loop of test suites in a CasperJS test file results in random failures in the shell

让人想犯罪 __ 提交于 2019-12-04 17:04:59
I would like check the title of several website. So, when I want do that with the "test object", I randomly get different results. I mean, when I run the shell command "casperjs test ..." : Sometimes, my shell displays all the test (its Ok!) Sometimes (screenshot #1), all tests is not done Sometimes (screenshot #2), I get a fail "check title" test, the previous open(url) didn't load the new url (?!) The screenshot of my shell: My code: casper.options.loadImages = false; var lines = [ "http://www.jeuxvideo.com;JEUXVIDEO.COM - La Référence des Jeux Vidéo sur PC et Consoles !", "http://www.google

Getting remote data for a page using AJAX in CasperJS

人盡茶涼 提交于 2019-12-04 12:10:03
问题 In the course of executing a CasperJS script I need to fetch and parse JSON data from another site so that I can use that data to fill in a form on the site I'm actively working on. How can I do this? 回答1: You can use __utils__.sendAJAX(): var casper = require('casper').create(); var wsurl = 'https://raw.github.com/n1k0/casperjs/master/package.json'; var word; casper.start('http://google.com/', function() { word = this.evaluate(function(wsurl) { try { return JSON.parse(__utils__.sendAJAX

Cannot navigate with casperjs evaluate and __doPostBack function

时间秒杀一切 提交于 2019-12-04 12:09:04
When I try to navigate the pagination on sites with links where href is a __doPostBack function call, I never achieve the page change. I am not sure what I am missing, so after a few hours of messing around I decided to see if someone here can give me a clue. This is my code (uber-simplified to show the use case). var casper = require('casper').create({ verbose: true, logLevel: "debug" }); casper.start('http://www.gallito.com.uy/inmuebles/venta'); // here i simulate the click on a link in the pagination list casper.evaluate(function() { __doPostBack('RptPagerDos$ctl08$lnkPage2',''); }); casper

CasperJS getElementsByXPath only returning first element

冷暖自知 提交于 2019-12-04 11:26:12
问题 I use the following code to get all table cells in the first table row. I'd like to then check the innerHTML of every single table cell. But in the object returned by this function only the first table cell is actually there, all the other properties are null: firstRow = this.evaluate(function () { return __utils__.getElementsByXPath('//tbody/tr[1]/td'); }); utils.dump(firstRow); The output from utils.dump is: [ { "abbr": "", "align": "", "attributes": {...} }, null, null, null ] I also tried

How to perfectly isolate and clear environments between each test?

久未见 提交于 2019-12-04 08:18:54
I'm trying to connect to SoundCloud using CasperJS. What is interesting is once you signed in and rerun the login feature later, the previous login is still active. Before going any further, here is the code: casper.thenOpen('https://soundcloud.com/', function() { casper.click('.header__login'); popup = /soundcloud\.com\/connect/; casper.waitForPopup(popup, function() { casper.withPopup(popup, function() { selectors = { '#username': username, '#password': password }; casper.fillSelectors('form.log-in', selectors, false); casper.click('#authorize'); }); }); }); If you run this code at least