0

I have ubuntu running in termux, I installed pycharm to create python code. The problem is I'm having some error opening the webdriver.

I have the latest firefox (v59.0.2), Selenium geckodriver v.0.24.0 and using python 3.6.5

This is the the code

from selenium import webdriver

driver = webdriver.Firefox('/root/Downloads/geckodriver')

Here is the error

Traceback (most recent call last):
   File "<input>", line 3, in <module>
   File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
  File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 80, in __init__
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
  File "/usr/lib/python3.6/shutil.py", line 309, in copytree
names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver'

and if I do this

from selenium import webdriver

driver = webdriver.Firefox(executable_path='/root/Downloads/geckodriver')

Here is the error

    Traceback (most recent call last):
    File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver': '/root/Downloads/geckodriver'
During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "<input>", line 3, in <module>
  File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/root/PycharmProjects/untitled/venv/lib/python3.6/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.
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33

2 Answers2

1

As per your first code trial this error message...

FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver'

...implies that your program was unable to locate the GeckoDriver within the mentioned directory.

You can find a detailed analysis on this error with in the discussion FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver' with GeckoDriver and Python in MAC OS

As per your second code trial this error message...

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

...implies that your program was unable to locate the GeckoDriver within the mentioned directory.

You can find a detailed analysis on this error with in the discussion WebDriverException: 'geckodriver' executable needs to be in PATH even though it is

Solution

Ideally you need to:

  • Ensure that GeckoDriver is having executable permission for non-root users.
  • Execute your @Tests as a non-root user.
  • Use the following code block:

    from selenium import webdriver
    
    driver = webdriver.Firefox(executable_path=r'/non_root_user/Downloads/geckodriver')
    driver.get("http://google.com/")
    driver.quit()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • for bullet 1 and 3, I have termux which is a `virtualenv` so its only `root` user not unless there is a way for me to check for the **non-root** user, I checked the permission and its all _read and write_ , I also tried to put it in `/usr/local/bin` and the result is `unexpectedly exited. Status code was: -4` and for the bullet 2 I don't know that, I'm a newbie – junichironakashima Aug 12 '19 at 13:47
0

Just copy the geckodriver files into your PATH. Type echo $PATH to find your PATH

t_kod_pq
  • 1
  • 1