Search code examples
javaselenium-webdriverphantomjsghostdriver

Execute JavaScript before page loads in PhantomJS driven by Selenium


I need to execute some javascript before the page page loads(= before the javascript on the page is executed)

Is that possible via ghostdriver? using phantomjsdriver 1.2.1 for java, phantomjs 2.0


Solution

  • No.

    PhantomJS is effectively a browser. You cannot edit a webpage in a browser before the browser has loaded it.

    Don't bother trying to disable JavaScript in PhatomJS either because then you won't be able to use JavaScript to inject the JavaScript you need before enabling JavaScript.