Python3.5 和 FF48 的 Selenium WebDriver 出现“无法加载配置文件”错误

2023-11-29

我正在尝试将 Selenium 与 Python 一起使用。
因此,我编写了以下代码并保存为名为的文件test.py在工作目录中/用户/ykt68/seleniumwork .

[ykt68@macbp15 seleniumwork]$ pwd
/Users/ykt68/seleniumwork
[ykt68@macbp15 seleniumwork]$ cat -n test.py
     1  #! /usr/bin/env python
     2  # -*- encoding: utf-8 -*-
     3  
     4  from selenium import webdriver
     5  from selenium.webdriver.common.keys import Keys
     6  
     7  driver = webdriver.Firefox()
     8  driver.get("http://www.python.org")
     9  assert "Python" in driver.title
    10  elem = driver.find_element_by_name("q")
    11  elem.clear()
    12  elem.send_keys("pycon")
    13  elem.send_keys(Keys.RETURN)
    14  assert "No results found." not in driver.page_source
    15  driver.close()
[ykt68@macbp15 seleniumwork]$

上面这些代码与2.1 简单使用在文件中硒与 Python.

当我运行上面的 test.py 的 python 命令时,

  • FireFox 浏览器启动并打开一个空白选项卡。
  • 大约 30 秒过去后,显示以下错误消息并关闭 FireFox 窗口。
[ykt68@macbp15 seleniumwork]$ python test.py 
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    driver = webdriver.Firefox()
  File "/Users/ykt68/.pyenv/versions/seleniumwork/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/Users/ykt68/.pyenv/versions/seleniumwork/lib/python3.5/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in    __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/Users/ykt68/.pyenv/versions/seleniumwork/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/Users/ykt68/.pyenv/versions/seleniumwork/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/86/55p1gj4j4xz2nw9g5q224bk40000gn/T/tmpf0uolidn If you specified a log_file in the FirefoxBinary constructor, check it for details.

[ykt68@macbp15 seleniumwork]$

请教我为什么会出现这个错误以及如何解决问题或列出一些我应该参考的帖子或文档。

此外,

  1. Environments:
    • 操作系统:Apple OS X 版本 10.11.6
    • Python版本:3.5.2
    • 火狐版本:48.0.2
    • 硒版本:2.53.6
[ykt68@macbp15 seleniumwork]$ python -V
Python 3.5.2
[ykt68@macbp15 seleniumwork]$ /Applications/Firefox.app/Contents/MacOS/firefox -v
Mozilla Firefox 48.0.2
[ykt68@macbp15 seleniumwork]$ /Applications/Firefox.app/Contents/MacOS/firefox-bin -v
Mozilla Firefox 48.0.2
[ykt68@macbp15 seleniumwork]$ pip list
pip (8.1.2)
selenium (2.53.6)
setuptools (20.10.1)
[ykt68@macbp15 seleniumwork]$
  1. 我参考了类似的帖子Selenium:FirefoxProfile 异常无法加载配置文件。所以我尝试了
pip install -U selenium

但上述错误信息的情况没有改变。

此致。


根据我的理解和结论,你可以保留最新的selenium软件包版本,但你必须将 Firefox 降级至 47 (47.0.1是 47 分支的最新稳定版)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python3.5 和 FF48 的 Selenium WebDriver 出现“无法加载配置文件”错误 的相关文章

随机推荐