Prosunjit Biswas
Prosunjit Biswas

Reputation: 1111

Browser Instrumentation

I need to mimic the behavior of a browser. For Say I need to acess the DOM properties of a webpage (ex. Document.cookie or window.onblur etc) without loading a webpage in an actual browser and without interacting (ex. clicking button, putting mouse over a link etc) in the browser.

Infact, I am trying to do some thing where I have an imaginary browser Object BROWSER. So, I can do :

BROWSER g = BROWSER.load('google.com');
g.document.cookie();
g.window.onblur();

I guess this is known as 'browser instrumentation'. How Can I do it ? Any ideas.. ?

Upvotes: 1

Views: 985

Answers (2)

JCarter
JCarter

Reputation: 407

Is this something you're looking for? It's called PhantomJS

From the site:

Full web stack, No browser required

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

Run functional tests with frameworks such as Jasmine, QUnit or CasperJS.

Upvotes: 2

machineghost
machineghost

Reputation: 35760

Your best bet is probably Selenium (http://seleniumhq.org/). Although it does use a real browser (which is sort of necessary if you want to test things in a real browser environment), it will allow you to completely automate/control that browser to make it do whatever you want. Using it you can write code like this:

# Pseudo-code to search for Selenium on Google
browser.open('www.google.com')
browser.findElementByCSS('#search').value('Selenium')
browser.findElementByCSS('#submitButton').click()

which sounds like what you are trying to do.

Upvotes: 2

Related Questions