PhantomJS – Webpage Module Methods
”;
The Web Page Module has methods for Cookies, Frames, Page Navigation, Reload, Rendering and Uploading of Files.
Following are the methods available on the web page.
S.No | Methods & Description |
---|---|
1 | addCookie()
addCookie method adds cookies to the page specified. |
2 | childFramesCount()
This method is deprecated as per http://phantomjs.org. |
3 | childFramesName()
This method is deprecated as per http://phantomjs.org. |
4 | clearCookies()
Will delete all the cookies for the page specified. |
5 | close()
This method is used to close the page and release the memory used. Any of the webpage methods or properties will not work once the close is called. |
6 | currentFrameName()
This method is deprecated as per http://phantomjs.org. |
7 | deleteCookie()
This will delete a cookie with the name matching with the existing list of cookies present for a given page url. |
8 | evaluateAsync()
Evaluate given function asynchronously within the page without blocking current execution. This function helps to execute certain scripts asynchronously. |
9 | evaluateJavascript()
EvaluateJavaScript helps to execute the function passed to it as a string. Please note the string passed has to be a function only. |
10 | evaluate()
Evaluate will execute the function passed to it. If the function contain console messages it is not displayed directly in the terminal. To display any console messages you need to use onConsoleMessage phantom callback. |
11 | getPage()
This will give you the child page that matches the windowname passed in getpage. |
12 | goBack()
It gives the previous page in navigation history, if only the navigation is not locked. |
13 | goForward()
It gives the next page in navigation history, if only the navigation is not locked. |
14 | go()
This method allows you to navigate with the pages. |
15 | includeJs()
Includejs executes the external JS file on page and executes the callback function on completion. |
16 | injectJs()
InjectJs includes external script from a specified file into the page. If the file is not available in the current directory, then it used libraryPath for additional search of the file. It returns true if the file is injected, otherwise false. |
17 | openUrl()
OpenUrl opens up a webpage. It is similar to open method of PhantomJS. OpenUrl has some additional parameters, which are httpConf, settings and callback functions. |
18 | open()
Open is used to open up a webpage. |
19 | release()
Release will release the memory heap usage for the page. Do not use page instance methods after the release is called. This method is similar to the close method and the usage of it is deprecated. Instead use wpage.close(). |
20 | reload()
Reload is used to reload the current page used. |
21 | renderBase64()
This method takes the screen capture and gives the image as a string in base46. Renderbase64 supports format like PNG, JPEG and JPG. It does not support gif as of now. You can use clipRect property to define the portion for image capture. |
22 | renderBuffer()
RenderBuffer takes the capture of the webpage to an image buffer, which can be directly sent to the server. Formats supported are PNG, GIF and JPEG. |
23 | render()
Render helps to take the image buffer and save it as per the format specified. |
24 | sendEvent()
It is used to send an event to the webpage. They are not dom events. Each of these events are sent to the webpage based on user interaction. |
25 | setContent()
setcontent will change the page content of the specified url with the contents specified. |
26 | stop()
It helps to stop loading of the page. |
27 | switchToChildFrame()
It is deprecated to use switchToFrame(); |
28 | switchToFocusedFrame()
It selects the frame, which is in focus. |
29 | switchToFrame()
Selects frame with the name specified and which is child of current frame. |
30 | switchToMainFrame()
Selects mainframe i.e. the root window. |
31 | switchToParentFrame()
It takes the parent frame of the current child frame. |
32 | uploadFile()
This method is used to handle the file upload done using form in html. PhantomJS does not have a direct way to do so using forms the same can be achieved using uploadFile method. It takes html tag selector for file location and the destination where it has to be copied. |
”;