H
H
HexUserHex2020-06-24 10:28:13
Python
HexUserHex, 2020-06-24 10:28:13

Selenium doesn't see the driver specified in webdriver.Firefox()?

Good afternoon,
I have already used selenium several times, but at the moment I don’t understand what I missed, I downloaded the necessary driver for Firefox, put it in the selenium_driver directory next to the script, below I will give an example script

#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox(executable_path=r'/var/www/html/parsers/selenium_driver/geckodriver')
driver.get("https://www.python.org")


Checking that the path is valid and the driver file exists:
bash-5.0# file /var/www/html/parsers/selenium_driver/geckodriver
/var/www/html/parsers/selenium_driver/geckodriver: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.26, BuildID[sha1]=32c4cfc2d9346336dc7c20e99a62df9be344d609, with debug_info, not stripped


On startup, I get errors that PATH is not correct, and selenium does not see the driver file, I tried using a relative path to the driver:
driver = webdriver.Firefox(executable_path=r'selenium_driver/geckodriver')
or
driver = webdriver.Firefox(executable_path=r './selenium_driver/geckodriver')
but the result is the same.
bash-5.0# ./selenium_get.py 
Traceback (most recent call last):
  File "/root/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/root/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/root/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 1522, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/var/www/html/parsers/selenium_driver/geckodriver': '/var/www/html/parsers/selenium_driver/geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./selenium_get.py", line 6, in <module>
    driver = webdriver.Firefox(executable_path=r'/var/www/html/parsers/selenium_driver/geckodriver')
  File "/root/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/root/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question