mrkeck Sharing the Love

28Jul/161

Phantomjs – command not found

Using a Mac, downloaded the zip and unzipped. Then tried to run phantomjs but said "Command not found" eventhough I was in the directory. If I used ./phantomjs in the dir it worked fine. No idea why

Filed under: phantomJs 1 Comment
2Dec/131

casperJs not finishing on Windows

On Windows Laptop CasperJs would not finish but had no errors.
Strangely had to do with the NVIDIA Graphics Card
To fix:
Open NVIDIA Control Panel
Manage 3D Settings
Global Settings tab
Preferred Graphics Processor: High-performance NVIDIA performance

Filed under: casperJs 1 Comment
1Dec/120

jQuery Full Position of Element on Page

var eleBounds=function(ele){
	ele=$(ele);
	var off=ele.offset();
	var bounds={};
	bounds.top=off.top;
	bounds.bottom=bounds.top+ele.height();
	bounds.left=off.left;
	bounds.right=bounds.left+ele.width();
	bounds.height=ele.height();
	bounds.width=ele.width();
	return bounds;
}

Works well with phantomJS clipRect, just have to get the function in the page and return back the object and set clipRect equal to it.

Filed under: jquery, phantomJs No Comments
26Nov/120

Javascript sleep function

var sleepyTime=10*1000;  //10 seconds
setTimeout(function(){
//In 10 seconds this will alert("I'm awake!");
alert("I'm awake!");
},sleepyTime);
12Nov/120

phantomJs delay until condition is met

var tries=0;
var maxTries=10;
var howOften=2000;
var tom=setInterval(function(){
	tries++;
	delayResponse=page.evaluate(function(){
		//console.log('Searching');
		return $('#thingy').length>0;
	});
	if(delayResponse || maxTries<=tries){
		//console.log('Found it or out of time');
		clearInterval(tom);
		//Do stuff now that it is ready
	}
},howOften);

There is a function out there called waitFor but I found this easier to handle