0

I want to run some selenium program (pythonas.py) which starts with:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

firefox_binary_path = '/usr/bin/firefox'

options = Options()
options.binary_location = firefox_binary_path
service = Service(executable_path='/usr/bin/geckodriver')

driver = webdriver.Firefox(options=options, service=service)

it crashes in webdriver.Firefox() like:

Traceback (most recent call last):
  File "pythonas.py", line 13, in <module>
    driver = webdriver.Firefox(options=options, service=service)
  File "/home/jk/.local/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 68, in __init__
    super().__init__(command_executor=executor, options=self.options)
  File "/home/jk/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "/home/jk/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 291, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "/home/jk/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "/home/jk/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

I have wsl linux on windows, selenium 4.10 and geckodriver of the version geckodriver-v0.33.0-linux64.tar.gz. The paths for firefox and geckodriver are correct.


I tried, for example, writing

driver = webdriver.Firefox()

instead. But the output was always the same. I also read posts describing similar issues and tried what the answers suggest, but couldn't solve the problem. What could it be?

John Kall
  • 3
  • 3
  • Have you tried running `/usr/bin/firefox` and `/usr/bin/geckodriver` in the temrinal, to see if they display any useful error messages? – John Gordon Jul 01 '23 at 15:13
  • If I write 'which firefox' is prints '/usr/bin/firefox' but if I write '/usr/bin/firefox' it says 'Error: no DISPLAY environment variable specified'. '/usr/bin/geckodriver' prints '1688225340276 geckodriver INFO Listening on 127.0.0.1:4444' and it doesn't terminate. – John Kall Jul 01 '23 at 15:28
  • Then that sounds like the root cause of the exception. Fix your `DISPLAY` environment variable. Problem solved! – John Gordon Jul 01 '23 at 15:29
  • Should I get an X server like Xming? – John Kall Jul 01 '23 at 16:58
  • You need an X display server running on your local machine, and you need to enable X tunnel/forwarding on your connection to the remote machine. – John Gordon Jul 01 '23 at 17:08
  • wsl just have terminal, it have no gui, so it does not provide a full desktop experience, maybe you should install a gnome. or you can try using the win10 not the linux – Jiu_Zou Jul 02 '23 at 12:31
  • I got an X server and I can open firefox, use xeyes, xcalc etc, but I still get the same output, just with a different message at the end: "Failed to decode response from marionette". Also when I open firefox through the terminal. get the message: " [GFX1-]: glxtest: cannot access /sys/bus/pci [GFX1-]: glxtest: libEGL no display ". – John Kall Jul 04 '23 at 15:16
  • "options.add_argument("--headless")" fixes the problem. So the problem must be related to the errors " [GFX1-]: ..." – John Kall Jul 05 '23 at 10:52

1 Answers1

0

Using and the Service class you don't require the executable_path key. So your working code block will be:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

firefox_binary_path = '/usr/bin/firefox'
options = Options()
options.binary_location = firefox_binary_path
s = Service('/usr/bin/geckodriver')
driver = webdriver.Firefox(service=s, options=options)

While using Selenium v 4.6 and above, Selenium Manager being integrated you no more require to pass the **Service** object and you can simply:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_binary_path = '/usr/bin/firefox'
options = Options()
options.binary_location = firefox_binary_path
driver = webdriver.Firefox(options=options)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352