0

I am trying to install firefoxdriver webdriver for python3 selenium on Ubuntu18.04

I followed this link : https://linuxhint.com/selenium-web-automation-python/

However, when I execute the following code :

from selenium import webdriver    
driver = webdriver.Firefox()
driver.get('http://google.com')
driver.quit()

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

So I tried putting the path of where my geckodriver was :

driver = webdriver.Firefox('/usr/bin')

I get this error and the array of X11 continues for more lines:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/usr/local/lib/python3.6/dist-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 365, in copytree
    raise Error(errors)
shutil.Error: [('/usr/bin/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/cc', '/tmp/tmpl7s73h44/webdriver-py-profilecopy/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/cc', "[Errno 40] Too many levels of symbolic links: '/usr/bin/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/cc'"), ('/usr/bin/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/rlogin', '/tmp/tmpl7s73h44/webdriver-py-profilecopy/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/rlogin', "[Errno 40] Too many levels of symbolic links: '/usr/bin/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/rlogin'"), ('/usr/bin/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/lzcmp', '/tmp/tmpl7s73h44/webdriver-py-profilecopy/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/X11/lzcmp',  .... ]

This is what I get in the geckodrive log :

1592310166221   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileANzvHL"
Running Firefox as root in a regular user's session is not supported.  ($XAUTHORITY is /run/user/1000/gdm/Xauthority which is owned by user.)

What am I doing wrong ?? How can I install the webdriver correctly?

When I tried with Chromedriver with the code:

>>> from selenium import webdriver
>>> from selenium.webdriver.chrome.options import Options
>>> options = Options()
>>> options.add_argument('--no-sandbox')
>>> options.add_argument('--disable-dev-shm-usage')
>>> d = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=options)

I get this error :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Reda
  • 55
  • 1
  • 7
  • it may need full path to file `'/usr/bin/geckodriver'` and probably it has to be with `firefox_binary=` or `executable_path=` - `Firefox(executable_path='/usr/bin/geckodriver)` - if you use without `executable_path=` then it may use it as `firefox_profile=`. Run in code `help(webdriver.Firefox.__init__)` and you will see that first value is assigned to `firefox_profile=` – furas Jun 16 '20 at 13:33
  • I tried all this but all gave me unsuccessful results. I am trying with the chromedriver now but it is giving me unsuccessful results as well (question edited) – Reda Jun 16 '20 at 13:42
  • first check if you install correct driver's version for correct browser's version - newer Chrome needs newer driver. Old driver will not work with new browser. I keep driver in my folder `~/bin` and I have `~/bin` in `PATH` so I don't have to use `executable_path=` – furas Jun 16 '20 at 13:44
  • BTW: do you have file `/usr/bin/chromedriver` or it is only folder and file is `/usr/bin/chromedriver/chromedriver` ? `executable_path=` need full path to file, not to folder. But `PATH` needs path to folder. – furas Jun 16 '20 at 13:47
  • my file is chromedriver so /usr/bin/chromedriver is the path to the file not to an entire folder – Reda Jun 16 '20 at 13:51
  • I installed all the latest version for chrome driver, firefox driver and chrome and firefox. So the versions should not be a problem – Reda Jun 16 '20 at 13:51
  • first error shows `Running Firefox as root in a regular user's session is not supported.` Do you run it as normal use or as root user or with `sudo` ? – furas Jun 16 '20 at 13:55
  • I don't know if this can be important but for `firefox` and `chromium-browser` I have privilages `-rwxr-xr-x` and owner `root:root`. Drivers I keep in `~/bin` and they have also `-rwxr-xr-x` but owner `furas:furas` – furas Jun 16 '20 at 14:00
  • So, the trick is you probably calling regular firefox instead of headless one (as from terminal) so you missing firefox options – rapttor Jul 29 '20 at 13:30

0 Answers0