11

I'm currently using Selenium Webdriver to do some validation on pages. The Webdriver is being driven by PhantomJS. I know that in PhantomJS, you can listen to the network using the example like the one below: (from https://github.com/ariya/phantomjs/wiki/Network-Monitoring).

var page = require('webpage').create();
page.onResourceRequested = function (request) {
    console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
    console.log('Receive ' + JSON.stringify(response, undefined, 4));
};
page.open(url);

How can I achieve this functionality within the Webdriver? Can I bind a function to the DesiredCapabilities?

2

1 Answer 1

0

What are you trying to achieve here? It is possible to inject javascript. So with that you could create a object that listens to the page and logs this into an object that you grab later on when you made some actions.

Ill give it a try but I'm not sure what phantomJS does.

browser.execute_script("    
var requests= [];
var received = [];
var page = require('webpage').create();
page.onResourceRequested = function (request) {
    requests.push('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
    received.push('Receive ' + JSON.stringify(response, undefined, 4));
};
page.open(url);");

Later (if your still on the same page) to get the requests:

browser.execute_script("function(){return requests }()");

and the received connections:

browser.execute_script("function(){return received}");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.