python - Selenium WebDriver 无法加载配置文件

标签 python firefox selenium

我尝试使用 Selenium WebDriver 启动 Firefox 并收到以下错误:

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
<ipython-input-10-9e1140c380e1> in <module>()
----> 1 t = tweepi.Tweepi(username, 0, profile_name)

/home/ubuntu/twitter/tweepi.pyc in __init__(self, username, threadid, profilename)
     22             profile = webdriver.FirefoxProfile(profilename)
     23             self.logger.debug('launching firefox')
---> 24             self.driver = webdriver.Firefox(firefox_profile = profile)
     25         else:
     26             self.driver = webdriver.Firefox()

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy)
     57         RemoteWebDriver.__init__(self,
     58             command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 59             self.binary, timeout),
     60             desired_capabilities=capabilities,
     61             keep_alive=True)

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
     45         self.profile.add_extension()
     46 
---> 47         self.binary.launch_browser(self.profile)
     48         _URL = "http://%s:%d/hub" % (HOST, PORT)
     49         RemoteConnection.__init__(

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in launch_browser(self, profile)
     62 
     63         self._start_from_profile_path(self.profile.path)
---> 64         self._wait_until_connectable()
     65 
     66     def kill(self):

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in _wait_until_connectable(self)
    106                 raise WebDriverException("Can't load the profile. Profile "
    107                       "Dir: %s Firefox output: %s" % (
--> 108                           self.profile.path, self._get_firefox_output()))
    109             count += 1
    110             time.sleep(1)

WebDriverException: Message: "Can't load the profile. Profile Dir: /tmp/tmp4nBIo5/webdriver-py-profilecopy Firefox output: None" 

现在,我在 stackoverflow 上找到的所有其他类似线程都说解决方案是使用命令更新 selenium

pip install -U selenium

这解决了我本地计算机上的问题,但问题仍然存在于我在 AWS 上的远程计算机上。这两台计算机具有相同的 Firefox 版本,都具有最新的 selenium,它们甚至在 ~/.mozilla/firefox 上具有完全相同的配置文件文件夹。

有什么建议吗?

编辑:

我可以在没有配置文件的情况下启动 Firefox。也就是做

w = webdriver.Firefox()

工作,同时做

profile_name = '/home/ubuntu/.mozilla/firefox/amozqob6.profile6'
profile = webdriver.FirefoxProfile(profile_name)
w = webdriver.Firefox(firefox_profile=profile)

得到上面的错误信息。

编辑2:

直接运行 Firefox 可执行文件:

firefox -profile ~/.mozilla/firefox/amozqob6.profile6

最佳答案

帮助我指定二进制文件 firefox 的显式路径

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary("/home/teddy/firefox/firefox")
driver = webdriver.Firefox(firefox_binary=binary)

关于python - Selenium WebDriver 无法加载配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126588/

相关文章:

python - 输入数据集和输出数据集的 Tensorflow image_dataset_from_directory

Python 3 项目间导入不起作用

javascript - bootstrap 3 模态,焦点输入字段不适用于 firefox

ajax - 如何让浏览器提示保存密码?

java - Selenium : XPATH invalid when stocking it in a String

Selenium RC verifyTrue(selenium.isTextPresent (“string” ))

python - 面向对象

python - Bokeh 中的等高线图

python - 找不到带有 Selenium 的按钮

html - CSS选框,如何使文本从底部移动到顶部