11
votes

I've installed Firefox and Selenium on centos. I'm using Xvfb and pyvirtualdisplay to open the browser.

When I try to run selenium webdriver, I'm able to open a new display but as soon as I do

browser = webdriver.Firefox()

I get the error:

File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 134, in __init__
    self.service = Service(executable_path, log_path=log_path)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/service.py", line 45, in __init__
    log_file = open(log_path, "a+")
IOError: [Errno 13] Permission denied: 'geckodriver.log'

Any clues on what's going wrong here?

EDIT : After overcoming the permission error, I'm getting

Message: 'geckodriver' executable needs to be in PATH

9
does the user running the script has rights to create a file 'geckodriver.log' in the path of the script? - Ivan Chaer
Well, you are obviously not supposed to write into this log file since it is already opened by another process running o your PC (allow me to guess that it's your own Python program while using selenium). - barak manos
@IvanChaer : Well I'm logged in as a super user and I've installed Selenium using "sudo" as well. I'm running the commands in python shell and the scripts asking for permission as those of webdriver. - Pravesh Jain
@barakmanos : I'm running the commands in python shell and not running anything else at the time. The log file is not mine but accessed through the webdriver. - Pravesh Jain
apparently this can come from an incompatibility between your firefox and your selenium. try sudo pip install --upgrade selenium, and if the error is still there, try downgrading your gecko driver. - Ivan Chaer

9 Answers

5
votes

Apparently this can come from an incompatibility between your firefox and your Selenium. Try pip install --upgrade selenium, and if the error is still there, try downloading a different version of Firefox, or of the gecko driver.

Regarding the message:

'geckodriver' executable needs to be in PATH

You could set the path of the driver on the script:

ff_profile_dir = "/usr/local/selenium/webdriver/firefox"
ff_profile = selenium.webdriver.FirefoxProfile(profile_directory=ff_profile_dir)
driver = selenium.webdriver.Firefox(ff_profile)

Or, according to this answer, you could run, on Unix systems, on a bash-compatible shell:

export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step

On Windows you will need to update the Path system variable to add the full directory path to the executable geckodriver manually or command line(don't forget to restart your system after adding executable geckodriver into system PATH to take effect). The principle is the same as on Unix.

4
votes

I was having the same problem. I tried using Ivan Chaer's answer, but it didn't work. I tried a whole bunch of other things until I finally came across a working solution. All the time I had been trying to run Selenium, I had been using the interactive shell. When I tried putting the code in a script and then running it instead, everything worked fine.

I then noticed that a file named "geckodriver.log" had been created in the same directory as the script. That gave me an idea. I created a "geckodriver.log" file in C:\Program Files\Python36 and then using Selenium with Firefox no longer threw any errors.

4
votes

I had this same issue recently on a Windows 10 workstation. I fixed it by explicitly setting the service_log_path to a location I know I've got write access to:

browser = webdriver.Firefox( service_log_path="C:\\Users\\[username]\\AppData\\Local\\Temp\\geckodriver.log" )

2
votes

The following solution worked for me. In my case I was starting my Python script from within the Windows Notepad++ application. My geckodriver.exe was in the PATH and happened to be located in my C:\Python 27 folder. A full path to Firefox was also provided. Selenium, geckodriver and Firefox were all on the latest versions.

It turn out that the geckodriver.log file was being created here:

C:\Program Files (x86)\Notepad++\geckodriver.log

I found this by running Notepad++ as an Administrator. It was then able to create the file where it wanted. I then located the file and changed the file permissions to full access for the normal user account on Windows (it was set to be read only).

After doing this, I was able to run Notepad++ normally and the error was gone.

1
votes

I had this exact same error.

[Errno 13] Permission denied: 'geckodriver.log'

The problem was not at all with this .log file.
The real problem was that my script (.py file) and the geckodriver.exe were not located in the same folder.
Once I put them in the same folder, the problem was solved and the function was executed normally.

browser = webdriver.Firefox()

Hope this helps.

1
votes

I had the same issue while working with python IDLE.

I just ran IDLE shell as Administrator.

Now on running the commands below works fine.

from selenium import webdriver
browser = webdriver.Firefox()  #opens up a new Firefox window
0
votes

I had the exact same problem. I went on the selenium's pypi page. In the Drivers section they talk about geckodriver and you can find the link to the geckodriver executable that suits your browser and OS.

I just downloaded it, unzipped it and then placed the geckodriver.exe file in C:\Program Files\Python37 (Python37 is already in my PATH). And it now works fine.

0
votes

in my case, geckodriver.log was created on the script folder, but by root user, from a previous execution, them running again as a normal user python didn't have access to file and fail

0
votes

I was having the same problem trying to run an interactive shell exactly where my webdriver (I'm using Firefox's geckodriver) was and nothing happened, and what I came to the conclusion of is that the directory doesn't have writing privileges when you make it, therefore I set writing privileges using chmod (on Linux) and everything worked as intended. Be sure to check on privileges first to see if you can create the geckodriver.log file in the first place.