phantomjs

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');

Use “window.onload” in phantomjs

被刻印的时光 ゝ 提交于 2019-12-04 20:20:24
I'm scraping data from AJAX-based pages using PhantomJS through the npm-phantom module. Sometimes the data isn't loaded yet when phantom starts DOM traversal. How to insert something like window.onload = function() { ... } into the page.evaluate ? It returns me a function, but not the data. var phantom = require('phantom'); exports.main = function (url, callback) { phantom.create(function (ph) { ph.createPage(function (page) { page.open(pref + url, function (status) { page.evaluate(function () { // here var data = {}; data.one = document.getElementById("first").innerText; data.two = document

Selenium + PhantomJS in Python 2.7, file upload

余生颓废 提交于 2019-12-04 20:06:19
I've been struggling with this function for a few hours now and I can't get it to work in any way shape or form. Assume my element location and image path are correct at all times. (Seriously, I've been going over this for the past 4 hours, it's not the element location and it's not the file path.) What I started with was a sendkeys to the input element. This gave no error but caused the script to hang for ever; it wouldn't get past it and no images were being uploaded. I literally tried every single possible variation of the sendkeys method listed on the first 4 pages of Google when looking

How can I set the viewport size of PhantomJS through grunt & jasmine?

心不动则不痛 提交于 2019-12-04 20:03:14
I'm trying to test something using grunt + jasmine + phantomjs. This specific test requires a large viewport so the responsive styles render the large-screen version within phantomjs. I noticed in the grunt-contrib-jasmine plugin this code, which would seem to allow for setting phantomjs options: // Merge task-specific options with these defaults. var options = this.options({ ... phantomjs : {}, ... }); However, when I add this to my config in grunt it has no effect: options: { phantomjs: { viewportSize: { width: 2000, height: 1000 } } } The answer lies in the fact that viewportSize is an

Call function PhantomJs

…衆ロ難τιáo~ 提交于 2019-12-04 19:26:28
I'm new in Java Script and i need help :) I want to call function ( set_calendar_date() ) and then get page innerHTML. <a onclick="set_calendar_date('1'); return false;" href="#"> <span> 26/02 We </span> PhantomJs code : page.open(url, function (status) { if (status !== 'success') { console.log('Unable to access network'); } else { var events = page.evaluate(function () { // here i want to call set_calendar_date(); return document.getElementById('fs').innerHTML; }); var file= require('fs'); file.write('results.txt',events,'w+'); phantom.exit(); }}); It seems that the function set_calendar_date

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

mocha init timeout with mocha-phantomjs

て烟熏妆下的殇ゞ 提交于 2019-12-04 19:10:47
问题 I have the following testrunner.html : <html> <head> <title>Specs</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="/content/css/mocha.css" /> <script> function assert(expr, msg) { if (!expr) throw new Error(msg || 'failed'); } </script> <script src="/client/lib/require.js" type="text/javascript" data-main="/client/specs/_runner.js"></script> </head> <body> <div id="mocha"></div> </body> </html> The _runner.js looks like this: //

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 pdf to stdout

我的未来我决定 提交于 2019-12-04 18:48:50
问题 I am desperately trying to output a PDF generated by phantomJS to stdout like here What I am getting is an empty PDF file, although it is not 0 in size, it displays a blank page. var page = require('webpage').create(), system = require('system'), address; address = system.args[1]; page.paperSize = {format: 'A4'}; page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { page.render('

Connection refused when phantomjs is run on different machine than selenium hub

一曲冷凌霜 提交于 2019-12-04 17:52:28
Is it possible to have a selenium hub on one machine and an instance of phantomjs on a different computer that connects to the hub in the same manner as a selenium node? If I start a selenum hub and an instance of phantomjs on the same machine, I can successfully run tests. If I start a selenium hub and start a selenium node a different machine and run a test with firefox, the test is executed successfully. If I start a selenium hub and an instance of phantomjs on a different machine, phantomjs will successfully connect to the hub but refuses the connection when the hub tries to send a test.