casperjs

Running 'casperjs test' in phantom

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I have a file running in node which runs a local copy of PhantomJS as below shows: phantom.casperPath = 'node_modules/casperjs'; phantom.injectJs('node_modules/casperjs/bin/bootstrap.js'); var casper = require('casper').create({ viewportSize: config.viewportSize }); casper.test.begin('Runing tests here', 5, function suite(test) { // Tests here }); Without the casper.test.begin() my tests function fine. I have the correct version 1.1.0 which can use this test suite but I get the following error in my console: CasperError: casper.test

I need to extract all id values with casperjs

隐身守侯 提交于 2019-12-02 23:19:03
问题 id = casper.evaluate(function() { return Array.prototype.map.call(document.querySelectorAll("image"), function(e) {return e.getElementById();});}); this.echo(id); 回答1: --Update-- If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for. Example: var casper = require('casper').create(); var ids = []; function getIdsByClassValue() { // use your selector here eg. '.image'. var elems = document.querySelectorAll('input[type="submit"

关于casperjs调换窗口,引用jquery和step栈!

匿名 (未验证) 提交于 2019-12-02 21:53:52
首先,调换窗口用withPopup方法,调用了此方法后执行环境在这个step中暂时换到了新建的窗口,但是,在这个step执行结束,进行下一个step时,环境会自动转换到之前的环境中。代码实例如下: 对了,也可以直接用js语句对DOM进行操作,去掉target=”_blank”属性就可以了,这样也可以,但是并没有实现跳转窗口,而是让窗口不跳转,直接在元窗口上显示参考这篇文章 用js操作DOM实现 网站: http://www.biqukan.com/ 当然,withPopup方法的参数去看官方文档 var casper = require ( "casper" ).create({ pageSettings:{ userAgent: "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0" , loadImages: false } }); phantom.outputEncoding = "gbk" ; casper.start( "http://www.biqukan.com/" , function () { this .capture( "D:/图片/首页.jpg" ); this .click( "div.item:nth-child(1) > div:nth-child

PhantomJS/CasperJS site login, cookies are not accepted by PhantomJS

大憨熊 提交于 2019-12-02 21:02:57
I recently tried to login into a webiste that forces me to accept cookies. I'm using phantomJs and casperJs. I wrote a little script that should handle the login, but it redirects me to a site that tells me I have to accept cookies. Email and password are just placeholders. The site I want to login is https://de.buyvip.com/ . But I need to click the button Anmelden mit Amazon so I can login with my amazon account. The other login form does not work. (That leads to this long url, I just copied it from my browser) Can someone help me? Here is the script: var casper = require("casper").create()

File IO inside CasperJS

吃可爱长大的小学妹 提交于 2019-12-02 18:03:57
Is it possible do read/write files inside a CasperJS Script ? var fs = require('fs'); var data = fs.readFileSync('testdata.data', 'utf-8'); console.log(data); Calling casperjs fileio.js returns: 'undefined' is not a function Even after running npm install fs . Bonus point if not : explain why ? hexid CasperJS does not make use of NodeJS' fs module. Instead, it uses that of PhantomJS Here's a short example of how to use PhantomJS' filesystem module: var fs = require('fs'); var utils = require('utils'); var data = fs.read('testdata.dat'); utils.dump(data); 来源: https://stackoverflow.com/questions

I need to extract all id values with casperjs

梦想与她 提交于 2019-12-02 14:21:16
id = casper.evaluate(function() { return Array.prototype.map.call(document.querySelectorAll("image"), function(e) {return e.getElementById();});}); this.echo(id); --Update-- If you want get elements containing a specific class just use a helper function to scrape the elements you are looking for. Example: var casper = require('casper').create(); var ids = []; function getIdsByClassValue() { // use your selector here eg. '.image'. var elems = document.querySelectorAll('input[type="submit"]'); return Array.prototype.map.call(elems, function (e) { // change to the attribute you are looking for.

Frontend testing: what and how to test, and what tool to use?

和自甴很熟 提交于 2019-12-02 14:04:20
I have been writing tests for my Ruby code for a while, but as a frontend developer I am obviously interested in bring this into the code I write for my frontend code. There is quite a few different options which I have been playing around with: CasperJS Capybara & Rspec Jasmine Cucumber or just Rspec What are people using for testing? And further than that what do people test? Just JavaScript? Links? Forms? Hardcoded content? Any thoughts would be greatly appreciated. Carlos I had the same questions a few months ago and, after talking to many developers and doing a lot of research, this is

Does PhantomJS use QtWebKit or Blink?

早过忘川 提交于 2019-12-02 10:16:17
问题 Does PhantomJS (CasperJS) use WebKit or Chromium as default browser-driver? If WebKit, is it direct WebKit or qt or gtk? 回答1: PhantomJS is based on QtWebKit. The FAQ says: Q: Which WebKit version is used by PhantomJS? A: If you want to know HTML5/CSS3/other features supported by PhantomJS, using WebKit version is not a good idea. See Supported Web Standards documentation page for details. If you really like to get the WebKit version, find it via the user agent, run the examples/useragent.js.

CasperJS sends empty POST data to endpoint

故事扮演 提交于 2019-12-02 08:14:26
I'm using CasperJS to scrape a site, build a JSON object to organize the info scraped, and then POSTing such JSON object to a service (in PHP) that ETLs the info into a database. Here's the problem, whenever I try to send the JSON Object the, the object is empty, this is the code I'm using to send the info. casper.then(function(){ var productDetails = {}; this.each(products,function(self, product){ self.thenOpen(product, function(a){ productDetails = this.evaluate(getProductDetails); }); self.thenOpen('http://localhost.endpoint.lan/saveScrapingData.php', { method:'post', data: { name:'Alan',

How to download a file through a custom POST request with CasperJS

元气小坏坏 提交于 2019-12-02 06:56:22
I am writing a crawler and needs to download file generated after a form request using POST. I have successfully used this.download(url,'POST',Params) for regular forms. One of the sites has many fields using the same name, thus preventing me from using the regular download method. After trying a lot of things, I tried with $.ajax() and __utils.sendAJAX() to process the form like this: response = this.evaluate(function(){ url=... params = $('form#theirForm').serialize(); data = __utils__.sendAJAX(url, 'POST', params,false,{contentType:"application/x-www-form-urlencoded"}); return __utils__