0

I am working on a python project which include selenium. I am using firefox so I have downloaded geckodriver. I have also added this in Path:

enter image description here

When I am running the application, its running fine. But whenever I am running the application as admin, it starts giving me below errors:

Message: 'geckodriver' executable needs to be in PATH

I have already added driver in path. Then how come I getting this error.

Is there any way we can confirm if I have set the proper path to driver in windows environment variable. How can I start the application as admin.? Please help. Thanks

S Andrew
  • 5,592
  • 27
  • 115
  • 237
  • Does this answer your question? [Selenium using Python - Geckodriver executable needs to be in PATH](https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – JaSON Aug 17 '20 at 06:31

3 Answers3

2

I have resolved the issue by mentioning the path to driver and its log file in the python script itself:

driver = webdriver.Firefox(executable_path=r'C:\geckodriver.exe', log_path=r"C:\geckodriver.log")

It then started working fine

S Andrew
  • 5,592
  • 27
  • 115
  • 237
1

Could the case be that you have set the geckodriver to uservariables instead of systemvariable in the environment variables prompt?

Challe
  • 599
  • 4
  • 19
  • Let me reconfirm this. – S Andrew Aug 17 '20 at 06:44
  • I have added it in system variable but still getting the error. Is there anything we need to add in the python code to make it utilize the driver .? – S Andrew Aug 17 '20 at 06:50
  • @SAndrew, can you restart the system and check after setting path in system variable. – NarendraR Aug 17 '20 at 06:53
  • Yes I have restarted its not working. I had to give the full path to the driver from the python code itself and then it started working fine. Is there anyway we can test weather the driver is in the PATH or not – S Andrew Aug 17 '20 at 06:58
  • You could try to run `path` in cmd as your normal user and as administrator and check if both have the geckodriver in them. `$Env:Path` is the powershell alternative – Challe Aug 17 '20 at 08:17
1

Seems you have set the path in User variable so its working fine while running it using current user. But as an admin it can't recognized the path as its not there in system variable.

Set the path in System variable.

System environment variables are globally accessed by all users.

User environment variables are specific only to the currently logged-in user.

NarendraR
  • 7,577
  • 10
  • 44
  • 82
  • @S Andrew, You can use `import os for k, v in os.environ.items(): print(f'{k}={v}')` to print all environment variable and check the driver or directly access the path using `print(os.environ['PATH'])` – NarendraR Aug 17 '20 at 07:32