phantomjs

Cannot pass module functions to Page

戏子无情 提交于 2019-12-02 08:16:56
问题 I have a module called util with the methods getMutedColor and some others. getMutedColor relies on another called rand in the same module. page.includeJs('https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.10/d3.min.js', function() { var util = require('./util'); var svg = page.evaluate(pageContext.pageExec, data, meta, util); /** ... **/ } I can call util.getMutedColor() just fine within this scope but in my pageContext.pageExec function, util.getMutedColor no longer exists. The util parameter

why phantomjs code doesn't go through array?

巧了我就是萌 提交于 2019-12-02 08:10:51
问题 After running this code he save an infinite number of files with the source code of the first page("http://site1.com"), why he doesn't go through other links and doesn't stop ? var args = ["http://site1.com", "http://site2.com", "http://site3.com"]; var fs = require('fs'); var i = 0; function handle_page(file){ page.open(file,function(){ page.evaluate(function(){ fs.write(i + '.html', page.content, 'w'); }); setTimeout(next_page,100); }); } function next_page(){ var file = args.shift(); if(

How to change current page in Phantomjs using buttons? [duplicate]

最后都变了- 提交于 2019-12-02 07:17:05
This question already has an answer here: Open link in PhantomJS synchronously 1 answer I have start to using Phantomjs and I don't understand something. How to change current page using buttons? For example I've got a code: var page = require('webpage').create(); page.open('https://ru-ru.facebook.com', function() { page.injectJs('jQuery.js'); page.evaluate(function() { $('#email').val('MyLogin'); $('#pass').val('MyPass'); $('#u_0_l').click(); }); page.render('example.png'); phantom.exit(); }); So after clicking a button I need to go to the next page. How can I do this? Assuming the $.click()

PhantomJS evaluate with basic auth returning null

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 07:14:34
问题 I am trying to use PhantomJS on a page with basic always auth, for example, this page http://alexturpin.net/auth ( test:rosebud ) Using the following code var webpage = require('webpage'); page = webpage.create(); page.settings = { userName: "test", password: "rosebud" }; page.open("http://alexturpin.net/auth/", function(status) { console.log(status); var retval = page.evaluate(function() { return "test"; }); console.log(retval); }); I get this output $ phantomjs test.js success null Whatever

why phantomjs code doesn't go through array?

廉价感情. 提交于 2019-12-02 06:26:05
After running this code he save an infinite number of files with the source code of the first page(" http://site1.com "), why he doesn't go through other links and doesn't stop ? var args = ["http://site1.com", "http://site2.com", "http://site3.com"]; var fs = require('fs'); var i = 0; function handle_page(file){ page.open(file,function(){ page.evaluate(function(){ fs.write(i + '.html', page.content, 'w'); }); setTimeout(next_page,100); }); } function next_page(){ var file = args.shift(); if(!file){ phantom.exit(0); } i++ handle_page(file); } next_page(); page.evaluate() is the sandboxed page

Set a string as the response of a webpage in phantomjs

孤人 提交于 2019-12-02 06:13:00
Hi what i am trying to do is not to get the webpage as page.open(url); but to set a string that has already been retrieved as the page response. Can that be done? Yes, and it is as easy as assigning to page.content. It is usually also worth setting a page.url (as otherwise you might hit cross-domain issues if doing anything with Ajax, SSE, etc.), and the setContent function is helpful to do both those steps in one go. Here is the basic example: var page = require('webpage').create(); page.setContent("<html><head><style>body{background:#fff;text:#000;}</style><title>Test#1</title></head><body>

page.set('content') doesn't work with dynamic content in phantomjs

℡╲_俬逩灬. 提交于 2019-12-02 06:12:35
问题 I tried to use phantomjs for screen capturing my page with node-phantom bridge. Here is what I'm trying: var phantom = require('node-phantom'); phantom.create(function (err, ph) { return ph.createPage(function (err, page) { return page.set('content', '<html><head></head><body><p>Hello</p></body></html>', function (err, status) { return page.render('./content.png', function (err) { ph.exit(); }); }); }); }); That works fine, but if I try to set content which contains javascript, that doesn't

How to ng-click an A directive in a PhantomJS test

纵饮孤独 提交于 2019-12-02 05:34:50
问题 App generated by Yeoman with angular-generator. Directive: angular.module('psApp').directive('scrollTop', function () { return { restrict: 'A', scope: true, template: '<a href="#" ng-click="click()" class="scroll-top"><span class="glyphicon glyphicon-arrow-up"></span> Back to top</a>', controller: ['$scope', '$element', '$document', function ($scope, $element, $document) { $scope.click = function () { $document.scrollTop(0, 500); }; }] }; }); Test: describe('Directive: scrollTop', function ()

Custom casperjs modules

和自甴很熟 提交于 2019-12-02 05:31:36
问题 I've extended my casperjs to use some new methods like this one : casper.getTxt = function(selector) { if(this.exists(selector)) { return this.getHTML(selector); } else { return ''; } }; I've to add these functions on every script that I write. so I made a new file custom.js on the same location where other modules( colorizer.js , mouse.js etc) were placed. custom.js has following code : var require = patchRequire(require); var casper = require('casper').create(); var getTxt = function

Phantom.js - Get Text Inside Alert Box

北慕城南 提交于 2019-12-02 05:21:06
Is it possible to get the text inside an alert box using Phantom.js? var page = require("webpage").create() , assert = require("assert"); page.open("http://www.mysite.com/page", function (status) { page.includeJs("jquery-1.10.2.min.js", function () { var alertText = page.evaluate(function () { //This should cause an alert dialog to appear $('button[type="submit"]').click(); //This doesn't work, but is there some equivalent to this? return $("alert").val(); }); assert.equal(alertText, "Thanks for clicking Submit!"); }); }); There's no way to get the message from the alert that way (there is no