This is embarrassing to ask because it seems like something with so slim chance of error. I wouldn\'t think this would be difficult, but I\'ve been plugging away at this for
I had the same problem running Python 3.4 on Windows Server 2012 R2. PhantomJS was failing to create the ghostdriver.log file. I followed these steps that fixed it for me:
Ran python REPL from the console while checking to see if the code that instantiated the driver was getting called successfully.
browser = webdriver.PhantomJS(executable_path='phantomjs.exe', desired_capabilities=argdc, service_args=svc_args)
This may have been a version issue for you, but since I just went through setting this up on my Windows 7 PC without issues I'm going to share my 'journey' here.
First of, I'm more used to the Mac/Linux Terminal and having the python package manager pip
at my disposal is essential to me. After installing Python 2.7.8 and adding ;c:\Python27
to my PATH I noticed that pip
isn't included with Python versions lower than 2.7.9, so I had to add it myself. Afterwards I added ;c:\Python27\Scripts
to my PATH.
After that fetching the python package selenium
was as easy as typing the following into the cmd:
pip install selenium
Then I downloaded the phantomjs-1.9.7-windows.zip
from here, unzipped it and placed it here:
C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe
From there I had a working Python 2.7/Selenium Webdriver/PhantomJS example for Windows 7.
from selenium import webdriver
import os
phantomjs_path = "C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe"
browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull)
browser.set_window_size(1400, 1000)
browser.get("https://stackoverflow.com/")
print browser.title
Note that I added the argument service_log_path=os.path.devnull
to the function webdriver.PhantomJS()
to prevent PhantomJS from creating a ghostdriver.log in the directory of the python file being executed.
Do you any other file or directory with a same name , or a file of coding (like .. phantomjs.py) which you have named same as phantomjs
is so then rename it to something else. i hope it works