Selenium phantomjs

PhantomJS is a headless browser that can be used with the Selenium web automation module. Unlike the FirefoxDriver or ChromeDriver, the browser stays totally invisible during the process.

It behaves just like the other browsers. To design the process, you can change the webdriver to ChromeDriver or FirefoxDriver and change it to PhantomJS once its working.

Related course
Selenium WebDriver and Python: WebTest Automation Course

Install PhantomJS
Like the other web drivers, it needs installation.
On Mac you can install PhantomJS using:

brew install phantomjs

On Windows or Linux, get PhantomJS from the official site.

Selenium PhantomJS
Example PhantomJS code:

from selenium import webdriver
import time
driver = webdriver.PhantomJS()
html = driver.page_source

After importing the selenium module, we create the webdriver object using

driver = webdriver.PhantomJS()

Then will This will work with both Python 2.7 and Python 3.

If you are on a Windows machine you can specify the path to the phantomjs executable:

driver = webdriver.PhantomJS("C://phantomjs.exe")

On Mac or Linux, simply create the driver using:

driver = webdriver.PhantomJS()