【问题标题】:selenium opening the wrong Firefox-based browserselenium 打开错误的基于 Firefox 的浏览器
【发布时间】:2016-03-09 16:38:18
【问题描述】:

我最近安装了 Waterfox 浏览器,它本质上是一个速度更快的 64 位 Firefox,它共享 Firefox 的用户数据文件夹。此后,使用 selenium 调用 Firefox,如下行所示,调用 Waterfox 浏览器:

from selenium import webdriver
browser = webdriver.Firefox()

片刻之后,程序崩溃,产生以下回溯:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 77, in __init__
    self.binary, timeout),
  File "C:\Python\lib\site-packages\selenium\webdriver\firefox\extension_conne
ction.py", line 49, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Python\lib\site-packages\selenium\webdriver\firefox\firefox_binary.
py", line 68, in launch_browser
    self._wait_until_connectable()
  File "C:\Python\lib\site-packages\selenium\webdriver\firefox\firefox_binary.
py", line 103, in _wait_until_connectable
    raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, ch
eck it for details.

有没有办法明确告诉 selenium 调用实际的 Firefox 浏览器(除非必要,我不倾向于修改系统注册表),而不是打开 Waterfox?

【问题讨论】:

    标签: python firefox selenium


    【解决方案1】:

    是的,试试这个:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    binary = FirefoxBinary('path/to/binary')
    driver = webdriver.Firefox(firefox_binary=binary)
    

    来自this question

    【讨论】:

    • 我尝试将 waterfox 用于我的 python 脚本,binary = FirefoxBinary('/usr/bin/waterfox-classic') 真正启动了 waterfox,但它没有加载页面,如果我将路径设置为标准 firefox,它通常会加载。我还需要改变什么,从 firefox 切换到 waterfox?
    【解决方案2】:

    我用它来调用firefox:

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    options = Options()
    options.headless = False
    SITE = "http://localhost/something_I_want_to_convert_with_hi-resolution.html"
    DPI = 2.5
    profile = webdriver.FirefoxProfile()
    profile.set_preference("layout.css.devPixelsPerPx", str(DPI))
    driver = webdriver.Firefox(options=options, firefox_profile=profile)
    
    driver.get(SITE)
    ...
    

    【讨论】:

      猜你喜欢
      • 2016-03-14
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多