15

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

Pravesh Jain
  • 4,128
  • 6
  • 28
  • 47
  • 1
    does the user running the script has rights to create a file 'geckodriver.log' in the path of the script? – Ivan Chaer Nov 07 '16 at 13:50
  • 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 Nov 07 '16 at 13:51
  • @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 Nov 07 '16 at 13:54
  • @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 Nov 07 '16 at 13:54
  • 2
    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 Nov 07 '16 at 14:07
  • @IvanChaer : I've done the first step. I don't quite understand the 2nd. What's a gecko driver ? – Pravesh Jain Nov 07 '16 at 14:09
  • Also getting the error after overcoming the permission error: Message: 'geckodriver' executable needs to be in PATH – Pravesh Jain Nov 07 '16 at 14:13
  • I added an answer with some ideas on how to deal with the new error: `'geckodriver' executable needs to be in PATH` – Ivan Chaer Nov 07 '16 at 14:54

10 Answers10

7

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" )

father_goose
  • 311
  • 3
  • 6
5

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.

Community
  • 1
  • 1
Ivan Chaer
  • 6,980
  • 1
  • 38
  • 48
  • Thanks. I added geckodriver in PATH as mentioned. After that, as I do `browser = webdriver.Firefox()`, I get `selenium.common.exceptions.WebDriverException: Message: connection refused` – Pravesh Jain Nov 08 '16 at 05:21
  • 1
    Moving geckodriver to /usr/local/bin did the trick. Thanks a lot! – Pravesh Jain Nov 08 '16 at 06:21
4

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.

2

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.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
2

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
M2Kishore
  • 1,690
  • 1
  • 6
  • 13
1

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.

0

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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Jaj
  • 1
  • 1
0

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

Rogelio Triviño
  • 5,961
  • 3
  • 22
  • 17
0

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.

0

Had the same problem with Permission denied: 'geckodriver.log'

Tried a few of the options above, to no avail.

I was launching my script as a bat file from Windows scheduler. By default this runs in windows\system32...where you don't want to put the log and is a protected path.

Fixed it by updating the bat file to move to the my source code python folder

cd "C:\Users\[username]\mypy"
python.exe simpleSelenium.py
pause