casperjs

How to select an option with CasperJS

本秂侑毒 提交于 2019-12-08 22:31:07
问题 I try to set select option attribute to selected. But I try to avoid using nth-child in CasperJS because there are bugs in PhantomJS's nth-child. So I try to use this as the subtitution of jQuery(css_path). function setSelectedCountry(i){ window.__utils__.echo("i :"+i); var query = "//*[@id='cboCountry']/optgroup[2]/option["+i+"]"; __utils__.getElementByXPath(query).setAttribute("selected","selected"); } But, when I evaluate that code by this way this.evaluate(setSelectedCountry, 5); The

Testing React Apps with Phantom/Casper

烂漫一生 提交于 2019-12-08 19:42:35
I'm diving into functional testing and attempting to get a few simple tasks working. The app is built in ReactJS and I've decided to use Phantom/Casper. The problem is that even the most basic tasks fail. In short, is there a trick for testing React apps with Phantom/Casper? I've installed Phantom (v.2.1.1) and Casper (v1.1.0-beta5). As a first attempt I created a simple script to capture an image: capture.js var casper = require('casper').create({ viewportSize: { width: 1024, height: 768 }, verbose: true, logLevel: "debug" }); casper.start('http://localhost:9494', function() { console.log(

Iterating over a grid with CasperJS

非 Y 不嫁゛ 提交于 2019-12-08 19:41:49
问题 I am trying to test CasperJS out, and are scraping a site which has a grid layout like: |Name |Name | |Title |Title | |Image |Image | |Something |Something | |---------------------- |Name |Name | |Title |Title | |Image |Image | |Something |Something | |---------------------- If I wasn't using CasperJS I would retrieve a list of all the contains (4 i this case) and then run a method on each container which could retrieve an object with the wanted properties. I just seem to have a hard time of

CasperJS: How do you click on all selected buttons?

只谈情不闲聊 提交于 2019-12-08 16:17:44
问题 I'm trying to use CasperJS as a web scraper, and there's a page with buttons that will load data when clicked. So, I'd like to click all of these buttons first and wait before actually making a query to grab all the necessary data. The problem is that with Casper, casper.thenClick(selector) clicks the first element. But how do you iterate and click each element based on the selector? Note that these buttons do not have ids. They all have generic class selectors. Ex. <h3> <span>Text 1</span>

Insert casper javascript data to CSV file

亡梦爱人 提交于 2019-12-08 13:50:07
问题 I want to pass data from casper JS to CSV file I am currently using fs = require('fs'); fs.write('test.csv', "name, title", "a"); fs.write('test.csv', name.trim()+","+title.trim(), "a"); this is inside a loop so there are many records but printing to the CSV file is not inserting to a new row. It currently writes like this and I only want 2 columns on this Name Title name1 name1 name2 title2 name3 title3 回答1: add linebreaks fs.write('test.csv', name.trim()+","+title.trim()+"\n", "a"); CSVs

casper.waitForSelector, timeout and error handling

社会主义新天地 提交于 2019-12-08 13:10:02
问题 I made a quick script to capture a screen shot from a list of Reddit posts. The script fetches the reddit urls from a json file(example shown below) and then visits each page to capture a screenshot. The script works well for the most. However, every once in a while it will hang/continue to run if casper.waitForSelector criteria is not met. Eventually it will stall the whole server. I thought I was doing sufficient error handling. How can I modify the script to ignore any page that doesn't

passing a python object into a casperjs script iterating over the object and returning a result object to python

ⅰ亾dé卋堺 提交于 2019-12-08 12:45:35
问题 I'm new to programing in languages more suited to the web, but I have programmed in vba for excel. What I would like to do is: pass a list (in python) to a casper.js script. Inside the casperjs script I would like to iterate over the python object (a list of search terms) In the casper script I would like to query google for search terms Once queried I would like to store the results of these queries in an array, which I concatenate together while iterating over the python object. Then once I

Getting page rload time using casperjs

妖精的绣舞 提交于 2019-12-08 12:39:43
问题 I'm trying to capture the page load time using casperjs. The page in question is login protected. Here is what I have so far: var casper = require('casper').create(); // Enter the login page, fill up the form and submit it casper.start('https://example.net/login', function () { // Fill the form this.fill('form[name=signin]', { 'user': 'username', 'passwd': 'password' }, false); // Submit the form by clicking the submit button this.then(function() { this.click('#sign_in'); }); }); // Now on

CasperJS and downloading a file via iFrame and JavaScript

僤鯓⒐⒋嵵緔 提交于 2019-12-08 12:31:01
问题 I have a script to test that - on click - generates an iFrame which downloads a file. How can I intercept the response with CasperJS? I already tried the sequence: casper.click('element'); casper.withFrame('frame', function(){ console.log(this.getCurrentUrl()); // only return about:blank, but should have URL console.log("content: " + this.getHTML()); // Yep, empty HMTL this.on('resource.received', function(resource){ console.log(resource.url); // never executed }); }); I need the content of

How to emulate mouseover or run JS function on page with PhantomJS in NodeJS

主宰稳场 提交于 2019-12-08 11:52:16
问题 NodeJS, PhantomJS, content parsing with Cheerio Need to parse webpage, that contains dynamically loaded div(hint). The event can be on many table td's, here is an example When I 'mouseover' on specific td I see this orange block with data, it's dynamically loaded with function, like this onmouseover="page.hist(this,'P-0.00-0-0','355svxv498x0x0',417,event,0,1)" I can view this info only after the page is loaded. Need to a specific row, only Marathonbet. When the function runs, the text is