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.
Browser Automation with Python Selenium
Like the other web drivers, it needs installation.
On Mac you can install PhantomJS using:
On Windows or Linux, get PhantomJS from the official site.
Example PhantomJS code:
After importing the selenium module, we create the webdriver object using
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:
On Mac or Linux, simply create the driver using: