selenium打开错误的基于Firefox的浏览器

时间:2015-12-04 16:57:56

标签: python firefox selenium

我最近安装了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?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

我用它来调用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)
...
相关问题