Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: [py] program hangs while instantiating Firefox #15356

Open
btdan opened this issue Mar 2, 2025 · 2 comments
Open

[🐛 Bug]: [py] program hangs while instantiating Firefox #15356

btdan opened this issue Mar 2, 2025 · 2 comments

Comments

@btdan
Copy link

btdan commented Mar 2, 2025

What happened?

Hello,I install selenium and geckodriver on Ubuntu24.04 system.
and then write the test program as follows:

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

geckodriver_path = '/usr/bin/geckodriver'
firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('-headless') # 无头模式,不显示浏览器窗口

try:
print("开始创建 Firefox Service 对象")
# 使用 Service 类来指定驱动程序的路径
service = Service(executable_path=geckodriver_path)
print("Firefox Service 对象创建成功")

print("开始创建 Firefox 浏览器实例")
browser = webdriver.Firefox(service=service, options=firefox_options)
print("Firefox 浏览器实例创建成功")

print("开始访问百度网站")
browser.get("http://www.baidu.com")
print("成功访问百度网站")

print("开始关闭浏览器")
browser.quit()
print("浏览器已关闭")

except Exception as e:
print(f"发生错误: {e}")

when I run the program .The program hold after print("开始创建 Firefox 浏览器实例").
That is to say, It is held on the setence: browser = webdriver.Firefox(service=service, options=firefox_options)
without anything tip.
Can anyone tell me how to solve this problem?
Thanks very much.

How can we reproduce the issue?

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

# 确认 geckodriver 路径是否正确
geckodriver_path = '/usr/bin/geckodriver'
firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('-headless')  # 无头模式,不显示浏览器窗口

try:
    print("开始创建 Firefox Service 对象")
    # 使用 Service 类来指定驱动程序的路径
    service = Service(executable_path=geckodriver_path)
    print("Firefox Service 对象创建成功")

    print("开始创建 Firefox 浏览器实例")
    browser = webdriver.Firefox(service=service, options=firefox_options)
    print("Firefox 浏览器实例创建成功")

    print("开始访问百度网站")
    browser.get("http://www.baidu.com")
    print("成功访问百度网站")

    print("开始关闭浏览器")
    browser.quit()
    print("浏览器已关闭")
except Exception as e:
    print(f"发生错误: {e}")

Relevant log output

No log output at all

Operating System

Ubuntu24.04

Selenium version

python 4.22.0

What are the browser(s) and version(s) where you see this issue?

Mozilla Firefox 135.0.1

What are the browser driver(s) and version(s) where you see this issue?

geckodriver 0.36.0 (a3d508507022 2025-02-24 15:57 +0000)

Are you using Selenium Grid?

no

Copy link

github-actions bot commented Mar 2, 2025

@btdan, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@cgoldberg
Copy link
Contributor

cgoldberg commented Mar 2, 2025

How long have you waited for it to start the browser? It doesn't sound like it has timed out, or else you would have seen an error/exception.

It is likely just taking time to download Firefox and/or GeckoDriver.

To further investigate further, please do the following:

  1. Upgrade to the latest version of selenium (currently 4.29), as we no longer support the version you are using.
  2. Enable DEBUG logging and try instantiating Firefox again. You can add the following lines of code before you call webdriver.Firefox to enable the console logs:
import logging
# This enables DEBUG logging for all modules globally
logging.basicConfig(level=logging.DEBUG)

This time, let it run for several minutes while it attempts to download the browser/driver. Post the console logs here.

@cgoldberg cgoldberg changed the title [🐛 Bug]: The program is held [🐛 Bug]: [py] program hangs while instantiating Firefox Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants