The error occurs only in CI/CD (Jenkins, GitLab CI) but works on your local desktop.
from selenium.webdriver.firefox.service import Service service = Service(executable_path='geckodriver.exe', service_args=['--log', 'debug']) service.start() # Manual start with longer timeout
from selenium.webdriver.firefox.service import Service service = Service(executable_path='path/to/geckodriver', port=7055) # Classic Selenium port driver = webdriver.Firefox(service=service) The error occurs only in CI/CD (Jenkins, GitLab
If you are reading this, you have likely been staring at a red, intimidating stack trace in your console. The error message, often truncated as cannot start the driver service on http://localhost when using Selenium with Firefox, is a classic automation roadblock.
from selenium import webdriver from selenium.webdriver.firefox.service import Service service = Service(executable_path=r'C:\drivers\geckodriver.exe') driver = webdriver.Firefox(service=service) from selenium import webdriver from selenium
firefox --version If this fails, Firefox cannot be found in your PATH .
sudo apt-get install xvfb xvfb-run python your_selenium_script.py Or, use PyVirtualDisplay in Python: is a classic automation roadblock.
This error is Selenium’s way of saying: “I tried to launch Firefox, but the bridge (GeckoDriver) connecting me to the browser collapsed before the connection could be established.”