1

I am using the Ghost driver with PhantomJS.

I need to get the http response code of the page thats loading the phantomjs. As its not straight forward to get that in the existing phantomjs implementation, I decided to override the page.onResourceRecieved function and get that response code.

But now I got struck that, it can be done easily if I am starting phantomjs with javascript in cli but not able to do it while starting in webdriver mode.

Is there a way to do that?

I tried following the things but both didn't work:

  1. I tried starting in webdriver mode with a javascript in cli with the following command:

    setup/phantomjs-1.9.8-macosx/phantomjs ../setup/config.js --webdriver=18824

    But in this approach it fails to start in webdriver mode.

  2. I tried to run the javascript to override the page.onResourceRecieved function but that is also not working. The below code doesn't throw any error or change anything:

    PhantomJSDriver driver = new PhantomJSDriver(caps);
    String script = "page.onResourceReceived = function(response) {  console.log('Response (#' + response.id + ', stage ' + response.stage + '): ' +response.url);};";
    Object result = driver.executePhantomJS(script);
    System.out.println(result);
    

Can anyone point me in the right direction to achieve this?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
vivek_jonam
  • 3,237
  • 8
  • 32
  • 44

0 Answers0