I got error 'chromedriver.exe executable needs to be in PATH' - python

I am using colab. I am trying to use selenium with python. I looked at different threads regarding adding the chromedriver to the PATH, which I did, but I keep getting the same error. I get two messages:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\bin\chromedriver.exe': 'C:\bin\chromedriver.exe'
WebDriverException: Message: 'C:\bin\chromedriver.exe' executable needs to be in PATH
Here is my screenshot of error: code error

You don't have the path set up properly.
Lucky for you this is doable through code. I used to do this all the time to have a portable swing application that run selenium on a shared project that ran on every laptop without explaining this stuff to them
# assign ChromeDriver path to variable
chrome = "/Users/Administrator/Downloads/chromedriver"
os.environ["webdriver.chrome.driver"] = chrome
I used to do it in Java but it should be doable on every language
https://www.approbotic.com/rpa/rpa/how-do-i-run-chrome-with-selenium-webdriver-in-python/#page-content
If you are using paths make sure that you are using the right arrows to indicate location \ isn't the same as \
How to get an absolute file path in Python

Related

Running selenium via geckodriver on raspberry pi 4 gives permission error [duplicate]

I've looked around checked both documentations and have found no answer.
I've been trying to use InstaPy a instagram api for python. After failing with multiple errors and assuming InstaPy is just having some issues so i tried to raw code it using selinium. after inserting the example code and alter it to my liking i just made sure this one would work. I received a new error instead of the old one saying the permissions may not be right. I have tried reinstall and running as admin but nothing works. how do i fix this and/or what does this mean
Code:
import time
from selenium import webdriver
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
Error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Webdrivers\RawBot.py", line 5, in <module>
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search path.
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
This error message...
WebDriverException: Message: 'Webdrivers' executable may have wrong permissions.
...implies that the ChromeDriver variant you are trying to use have wrong permissions.
You seem to have tried out:
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search system $PATH variable.
A few words:
If your underlying os is windows:
You have to download chromedriver_win32.zip from the ChromeDriver Download Location and unzip it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you have to append the binary extension as well, effectively i.e. chromedriver.exe.
While mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\\).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
If your underlying os is linux:
You have to download chromedriver_linux64 from the ChromeDriver Download Location and untar it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you don't have to provide any extension for the executable binary, effectively i.e. chromedriver.
While mentioning the Chromedriver binary path you have to use the single forward slash i.e. (/).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
If your underlying os is macos:
You have to download chromedriver_mac64 from the ChromeDriver Download Location and untar it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you don't have to provide any extension for the executable binary, effectively i.e. chromedriver.
While mentioning the chromedriver binary path you have to use the single forward slash i.e. (/).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
This got solved when you enter the full file name which is "chromedriver.exe". Try this if you are on windows
You just have to add
/chromedriver.exe
at the end of the path like this:
driver = webdriver.Chrome('C:/Users/User/Downloads/chromedriver_win32/chromedriver.exe')
Note: If you copy the path from "File Explorer" you will get:
C:\Users\User\Downloads\chromedriver_win32
You will need to use double backslashes like this:
C:\\Users\\User\\Downloads\\chromedriver_win32
so you don't get a syntax error. Or you can just use forward slashes.
If you are on a linux os, changing file permissions could possibly fix the problem. But beware of what you do with permissions:
chmod 755 "/path to chromedriver file"
I downloaded the file via python itself, which unfortunately disabled execution permission and this was the quick fix for it.
in Linux you need to specify the FULL path including the file itself as well, not just up to the folder (in Linux by default the downloaded file for chrome driver comes in a folder, e.g. 'chromedriver_linux64', open the folder and check the exact file name as well, usually 'chromedriver'):
from selenium import webdriver
chrome_driver_path = "/home/mn/chromedriver_linux64/chromedriver"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("https://www.amazon.com")
if you are using chrome you must specify the full path of the chromedriver.
search for the directory in which your chromedriver executable file resides.
click shift+right click on the executable file.
select "copy as path" and paste it in your script.
don't forget to use a double backslash
so it should be:
driver = webdriver.Chrome('C:\\Utility\\BrowserDrivers\\chromedriver.exe')
If you use a Mac OS Big Sur, and Chromedriver 90+, you might have an error with the permissions of your Chromedriver.
If this is the case, it's not the file permissions that you change via "chmod," instead, it is apple-store protection that forbids the execution of the web driver.
If you like to allow this driver to be used within your Python environment or via command-line, enter:
`$ sudo xattr -r -d com.apple.quarantine /usr/local/bin/chromedriver`
had same issue in django.
However when I ran the same code locally (not activating my django app) it was fine and didn't have to explicitly define the path to the chrome driver.
Got around it by explicitly defining the path and the chromederiver.exe
similar to the answer above.
path = "C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe"
in my case, since I want to eventually post my app I used dynamic paths
ie.
import os
BASE_oaAPP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_oaAPP_Utilities_DIR = os.path.join(BASE_oaAPP_DIR, 'mySubFolderInTheApp')
def utilsPathFileName(fileName):
return os.path.join(BASE_oaAPP_Utilities_DIR, fileName)
chrome_path = utilsPathFileName('chromedriver.exe')
driver = webdriver.Chrome(chrome_path)
WINDOWS : Giving complete file path solved problem.
Many tutorials and articles are recorded with previous versions, where you just give directory path containing web drivers. But now you also have to provide specific driver path you're using.
Instead of C:/WebDrivers give complete file path as C:/WebDrivers/chromedriver.exe
chmod 755 "/path to chromedriver file"
This has helped me
The same problem. My solution was in Linux os, Pycharm editor...
Make sure your webdriver file with other python files (such as selinum_driver.py)
Then just copy the path and paste it into your webdriver.Chrome('path')
Don't need to write webdriver.exe
driver = webdriver.Chrome('/home/raju/Documents/Python-selenium/chromedriver')
For WINDOWS 10: I ran into a similar situation with the same error message when running my test code in Visual Studio Code. What solved it for me was to close out of the VS Code app and re-open the app as an administrator via the right-click menu.
For me, none of the answers above worked. But moving the chromedriver.exe to a new path (desktop in my case) solved it.
path = "C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe"
I got the same error when wrongly installed drives(when for mac was downloaded windows drivers) once I correct it worked fine
You need to add exe at the end of the path of driver and it works.
locate your installed driver.exe,
shift+right click,
copy as path,
paste it to your IDE
we can fix this issue for centos
#Install package chromedriver. Install it using yum
yum install chromedriver
#Import following package in python.
from selenium import webdriver
#Add following options before initializing the webdriver
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=9222")
chromeOptions.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chromeOptions)
If you run it on a Windows computer you can also add it to Windows PATH (environment variables) so you don't have to declare executable_path. You can just say: webdriver.Chrome(options=your_options)
I got his error for MacOs and on changing the path to the one given below, the issue was solved.
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
I kept having this SAME problem after:
my script did not recognize chromdriver.exe in my $PATH (yes, it's there)
gave run permissions to exe
passed 'path/to/chromedriver.exe' into Chrome()
This is what solved it:
Don't give .exe in the python path(just provide up to the chromedriver in the path)
example:
driver = webdriver.Chrome("/Library/Frameworks/Python.framework/.../webdriver/chrome/chromedriver")
Unfortunately I still cant' get my script to read the chromedriver.exe path from my $PATH variable. Would still appreciate if someone helped out, although it's beyond the scope of this question
Windows users and visual studio code: while mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\).
as well use the exact path and add chromedriver.exe at the end of the path to point directly to the executable:
driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
or:
driver = webdriver.Chrome(r'C:\\Users\\wanja\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe')
this error means that file chromedriver is not executable,
I fix this error with run command of (in linux):
sudo chmod +777 chromedriver
It means to make the file executable by everyone with access.

Convert Python Script to exe and include selenium browser

I got problems while converting.
I tryed:
Auto py to exe - gui - I added chromedriver(1 file) || whole folder(site-packages\chromedriver_binary)
I created .spec file and wrote there:
a = Analysis(['tk.py'],
binaries=[],
datas=[("chromedriver.exe",".")])
But got some errors:
File "c:\python36_32\lib\site-packages\PyInstaller\building\buildne
782, in build with open(spec, 'r') as f: FileNotFoundError: [Errno 2]
No such file or directory: 'tkk.spec'
I have got .spec, chromedriver and python script in same folder.
When i'm run exe on Windows 7 i got something like it:
https://gyazo.com/0152ca0998e2e0895ff91c9cfb7db0c2
I have got no clue how to stop view of console to read error
Can you tell what's I'm doing wrong?
One way to preserve this error is to run tk.exe through the command prompt / terminal. On Windows this can be done by opening cmd, changing your directory to the location of tk.exe and executing ./tk.exe which will run the executable and preserve the output for you to see.
From what I can see (it's not clear), you are getting a FileNotFoundError saying "Nie mozna odnalezc okreslonego pliku" which I believe is The specified file can not be found in English. Below this, selenium has raised an error saying that chromedriver.exe cannot be found.
Looking at the video you provided, it looks like you used onefile mode. If you did some research on bundling files with PyInstaller's --onefile then you would know that you will need to tell selenium specifically where chromedriver.exe is.
I have not done this myself but I believe the process would look something like:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = resource_path('.')
driver = webdriver.Chrome(chrome_options=options)
Of course this won't be everything but this is telling selenium to look at the scripts temporary directory (due to --onefile) for chromedriver.exe
Also as a quick note, you said you used auto-py-to-exe. When using this tool, it tells you explicitly to take this into consideration when adding files and using --onefile.

Chromedriver working in path but not with selenium (python)

I've been attempting to use the selenium webdriver with Google Chrome.
I have installed chromedriver, and set the path to it. This has been done correctly as when I run chromedriver in terminal I get the output
Starting ChromeDriver 2.38.552518
on port 9515
Only local connections are allowed
However, when I attempt to use the chromedriver on my python script:
from selenium import webdriver
driver = webdriver.Chrome()
I get this following error:
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
I've tried multiple methods of specifying the direct path and also putting the chromedriver file in the folder the python script is in. But nothing seems to be working and they all give the same error!
Please Help!
edit:
Path has been set in bash profile as such:
export PATH="~/drivers/:${PATH}"
Attempted Path specified in the python script as such:
driver = webdriver.Chrome("~/drivers/chromedriver")
Still with the same error of:
No such file or directory: '~/drivers/chromedriver': '~/drivers/chromedriver'
Java can't understand ~/drivers/chromedriver, Because only Linux Shell understand ~ is user home folder, But Java can't.
So your should use absolute path like /home/<userA>/drivers/chromedriver or relative path like ../drivers/chromedriver
You have to set the Path :
driver = webdriver.Chrome('C:/path/to/chromedriver.exe')
download selenium server-standalone-3.12.0.jar
and try this in a terminal:
export CLASSPATH=".:selenium-server-standalone-3.12.0.jar"

'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I've looked around checked both documentations and have found no answer.
I've been trying to use InstaPy a instagram api for python. After failing with multiple errors and assuming InstaPy is just having some issues so i tried to raw code it using selinium. after inserting the example code and alter it to my liking i just made sure this one would work. I received a new error instead of the old one saying the permissions may not be right. I have tried reinstall and running as admin but nothing works. how do i fix this and/or what does this mean
Code:
import time
from selenium import webdriver
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
Error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Webdrivers\RawBot.py", line 5, in <module>
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search path.
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
This error message...
WebDriverException: Message: 'Webdrivers' executable may have wrong permissions.
...implies that the ChromeDriver variant you are trying to use have wrong permissions.
You seem to have tried out:
driver = webdriver.Chrome('C:\Webdrivers') # Optional argument, if not specified will search system $PATH variable.
A few words:
If your underlying os is windows:
You have to download chromedriver_win32.zip from the ChromeDriver Download Location and unzip it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you have to append the binary extension as well, effectively i.e. chromedriver.exe.
While mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\\).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
If your underlying os is linux:
You have to download chromedriver_linux64 from the ChromeDriver Download Location and untar it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you don't have to provide any extension for the executable binary, effectively i.e. chromedriver.
While mentioning the Chromedriver binary path you have to use the single forward slash i.e. (/).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
If your underlying os is macos:
You have to download chromedriver_mac64 from the ChromeDriver Download Location and untar it for usage.
Additionally, if you are explicitly specifying the Chromedriver binary path you don't have to provide any extension for the executable binary, effectively i.e. chromedriver.
While mentioning the chromedriver binary path you have to use the single forward slash i.e. (/).
So your effective line of code will be :
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
This got solved when you enter the full file name which is "chromedriver.exe". Try this if you are on windows
You just have to add
/chromedriver.exe
at the end of the path like this:
driver = webdriver.Chrome('C:/Users/User/Downloads/chromedriver_win32/chromedriver.exe')
Note: If you copy the path from "File Explorer" you will get:
C:\Users\User\Downloads\chromedriver_win32
You will need to use double backslashes like this:
C:\\Users\\User\\Downloads\\chromedriver_win32
so you don't get a syntax error. Or you can just use forward slashes.
If you are on a linux os, changing file permissions could possibly fix the problem. But beware of what you do with permissions:
chmod 755 "/path to chromedriver file"
I downloaded the file via python itself, which unfortunately disabled execution permission and this was the quick fix for it.
in Linux you need to specify the FULL path including the file itself as well, not just up to the folder (in Linux by default the downloaded file for chrome driver comes in a folder, e.g. 'chromedriver_linux64', open the folder and check the exact file name as well, usually 'chromedriver'):
from selenium import webdriver
chrome_driver_path = "/home/mn/chromedriver_linux64/chromedriver"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("https://www.amazon.com")
if you are using chrome you must specify the full path of the chromedriver.
search for the directory in which your chromedriver executable file resides.
click shift+right click on the executable file.
select "copy as path" and paste it in your script.
don't forget to use a double backslash
so it should be:
driver = webdriver.Chrome('C:\\Utility\\BrowserDrivers\\chromedriver.exe')
If you use a Mac OS Big Sur, and Chromedriver 90+, you might have an error with the permissions of your Chromedriver.
If this is the case, it's not the file permissions that you change via "chmod," instead, it is apple-store protection that forbids the execution of the web driver.
If you like to allow this driver to be used within your Python environment or via command-line, enter:
`$ sudo xattr -r -d com.apple.quarantine /usr/local/bin/chromedriver`
had same issue in django.
However when I ran the same code locally (not activating my django app) it was fine and didn't have to explicitly define the path to the chrome driver.
Got around it by explicitly defining the path and the chromederiver.exe
similar to the answer above.
path = "C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe"
in my case, since I want to eventually post my app I used dynamic paths
ie.
import os
BASE_oaAPP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_oaAPP_Utilities_DIR = os.path.join(BASE_oaAPP_DIR, 'mySubFolderInTheApp')
def utilsPathFileName(fileName):
return os.path.join(BASE_oaAPP_Utilities_DIR, fileName)
chrome_path = utilsPathFileName('chromedriver.exe')
driver = webdriver.Chrome(chrome_path)
WINDOWS : Giving complete file path solved problem.
Many tutorials and articles are recorded with previous versions, where you just give directory path containing web drivers. But now you also have to provide specific driver path you're using.
Instead of C:/WebDrivers give complete file path as C:/WebDrivers/chromedriver.exe
chmod 755 "/path to chromedriver file"
This has helped me
The same problem. My solution was in Linux os, Pycharm editor...
Make sure your webdriver file with other python files (such as selinum_driver.py)
Then just copy the path and paste it into your webdriver.Chrome('path')
Don't need to write webdriver.exe
driver = webdriver.Chrome('/home/raju/Documents/Python-selenium/chromedriver')
For WINDOWS 10: I ran into a similar situation with the same error message when running my test code in Visual Studio Code. What solved it for me was to close out of the VS Code app and re-open the app as an administrator via the right-click menu.
For me, none of the answers above worked. But moving the chromedriver.exe to a new path (desktop in my case) solved it.
path = "C:/Users/YOUR_USER/Desktop/chromedriver/chromedriver.exe"
I got the same error when wrongly installed drives(when for mac was downloaded windows drivers) once I correct it worked fine
You need to add exe at the end of the path of driver and it works.
locate your installed driver.exe,
shift+right click,
copy as path,
paste it to your IDE
we can fix this issue for centos
#Install package chromedriver. Install it using yum
yum install chromedriver
#Import following package in python.
from selenium import webdriver
#Add following options before initializing the webdriver
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("--headless")
chromeOptions.add_argument("--remote-debugging-port=9222")
chromeOptions.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/bin/chromedriver',chrome_options=chromeOptions)
If you run it on a Windows computer you can also add it to Windows PATH (environment variables) so you don't have to declare executable_path. You can just say: webdriver.Chrome(options=your_options)
I got his error for MacOs and on changing the path to the one given below, the issue was solved.
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
I kept having this SAME problem after:
my script did not recognize chromdriver.exe in my $PATH (yes, it's there)
gave run permissions to exe
passed 'path/to/chromedriver.exe' into Chrome()
This is what solved it:
Don't give .exe in the python path(just provide up to the chromedriver in the path)
example:
driver = webdriver.Chrome("/Library/Frameworks/Python.framework/.../webdriver/chrome/chromedriver")
Unfortunately I still cant' get my script to read the chromedriver.exe path from my $PATH variable. Would still appreciate if someone helped out, although it's beyond the scope of this question
Windows users and visual studio code: while mentioning the Chromedriver binary path you have to either use the single forward slash i.e. (/) along with the raw (r) switch or you have to use the escaped backslash i.e. (\).
as well use the exact path and add chromedriver.exe at the end of the path to point directly to the executable:
driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
or:
driver = webdriver.Chrome(r'C:\\Users\\wanja\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe')
this error means that file chromedriver is not executable,
I fix this error with run command of (in linux):
sudo chmod +777 chromedriver
It means to make the file executable by everyone with access.

Permission denied: 'geckodriver.log' while running selenium webdriver in python

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

Categories