PhantomJS - libraryPath Property



This property has the path, which is used by the page.inectJs method.

Syntax

Its syntax is as follows −

var wpage = require('webpage').create(); 
wpage.libraryPath = 'filepath'; 

Example

Take a look at the following example −

var webPage = require('webpage'); 
var page = webPage.create();  
page.open('http://www.tutorialspoint.com/jquery', function(status) { 
   if (status === "success") { 
      page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js ', function() { 
         if (page.injectJs('do.js')) { 
            var title = page.evaluate(function() { 
               // returnTitle is a function loaded from our do.js file - see below 
               return returnTitle(); 
            }); 
            console.log(title); 
            phantom.exit(); 
         } 
      }); 
   } 
}); 
window.returnTitle = function() { 
   return document.title; 
};

The above program generates the following output.

Jquery Tutorial 
phantomjs_webpage_module_properties.htm
Advertisements