PhantomJS - pages Property



The Pages property will you give an array of pages opened in a page using window.open. If the page is closed in the URL you referred, the page will not be considered.

Syntax

Its syntax is as follows −

var wpage = require('webpage').create(); 
wpage.pages; 

Example

Let us take an example to understand the use of page property.

var wpage = require('webpage').create(); 
wpage.open('http://localhost/tasks/ptitle.html', function (status) {  
   console.log(wpage.pages); 
   phantom.exit(); 
});

ptitle.html

<html> 
   <head> 
      <title>Testing PhantomJs</title> 
   </head> 
   
   <body> 
      <script type = "text/javascript"> 
         window.onload = function() { 
            window.open("http://localhost/tasks/a.html","page1"); 
            window.open("http://localhost/tasks/content.html", "page2"); 
         } 
      </script>  
      <h1>This is a test page</h1> 
   </body>
   
</html>

The above program generates the following output.

WebPage(name = "WebPage"),WebPage(name = "WebPage")

The webpage we are referring in the above example i.e. ptitle.html has two window.open commands. The output shows an array of pages from wpage.pages.

phantomjs_webpage_module_properties.htm
Advertisements