I am trying to use PhantomJS with Selenium and Python.
My understanding is:
I will have to write Python script utilizing Selenium package which will interact with Selenium to operate on PhantomJS WebDriver to automate web application testing.
I have installed following:
- Python v3.5.1.
- Selenium using
pip install selenium
v3.7.0. - PhantomJS v2.1.1
In meantime I tested using Chrome WebDriver by placing it in PATH, and it executes without errors. Following is my script to open google.com using chrome webdriver.
from selenium import webdriver
driver = webdriver.Chrome() # or add to your PATH
driver.get('https://google.com/')
Using PhantomJS:
from selenium import webdriver
url = "http://www.google.com"
path_phantom = r'H:\phantomjs\bin\phantomjs.exe'
driver = webdriver.PhantomJS(executable_path=path_phantom)
driver.get(url)
driver.save_screenshot(r'H:\out.png')
driver.quit()
Errors:
Traceback (most recent call last): File "C:\Users\acer\Desktop\testing\openYoutube.py", line 5, in driver = webdriver.PhantomJS() File "C:\Users\acer\AppData\Local\Programs\Python\Python35-32\lib\site-package s\selenium\webdriver\phantomjs\webdriver.py", line 51, in init log_path=service_log_path) File "C:\Users\acer\AppData\Local\Programs\Python\Python35-32\lib\site-package s\selenium\webdriver\phantomjs\service.py", line 50, in init service.Service.init(self, executable_path, port=port, log_file=open(log _path, 'w')) PermissionError: [Errno 13] Permission denied: 'ghostdriver.log'
Am I misplacing PhantomJS exe or missing any step ?