尝试在Mac上使用Selenium Firefox WebDriver时,“例外:在无”处找不到扩展名

时间:2010-04-18 06:09:12

标签: python macos firefox selenium webdriver

有什么想法吗?

In [1]: from selenium.firefox.webdriver import WebDriver

In [2]: d=WebDriver()
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)

/usr/local/selenium-read-only/<ipython console> in <module>()

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/selenium-2.0_dev-py2.6.egg/selenium/firefox/webdriver.pyc in __init__(self, profile, timeout)
     48             profile = FirefoxProfile(name=profile)
     49         if not profile:
---> 50             profile = FirefoxProfile()
     51         self.browser.launch_browser(profile)
     52         RemoteWebDriver.__init__(self,

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/selenium-2.0_dev-py2.6.egg/selenium/firefox/firefox_profile.pyc in __init__(self, name, port, template_profile, extension_path)
     72 
     73         if name == ANONYMOUS_PROFILE_NAME:
---> 74             self._create_anonymous_profile(template_profile)
     75             self._refresh_ini()
     76         else:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/selenium-2.0_dev-py2.6.egg/selenium/firefox/firefox_profile.pyc in _create_anonymous_profile(self, template_profile)
     82             self._copy_profile_source(template_profile)
     83         self._update_user_preference()
---> 84         self.add_extension(extension_zip_path=self.extension_path)
     85         self._launch_in_silent()
     86 

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/selenium-2.0_dev-py2.6.egg/selenium/firefox/firefox_profile.pyc in add_extension(self, force_create, extension_zip_path)
    152                 not os.path.exists(extension_source_path)):
    153                 raise Exception(
--> 154                     "No extension found at %s" % extension_source_path)
    155 
    156             logging.debug("extension_source_path : %s" % extension_source_path)

Exception: No extension found at None

3 个答案:

答案 0 :(得分:1)

好的,我已经通过手动创建webdriver-extension.zip文件并将其复制到我的site-packages目录中的selenium/firefox文件夹来超越此异常。

以下所有内容假设您从http://selenium.googlecode.com/svn/trunk/获得了源代码的副本(使用subversion / svn)

如果你安装了Ruby,你可以运行rake firefox(那是Ruby make),这是你应该构建zip文件的方式。由于我没有安装ruby,我只是查看/Rakefile并找出了应该在zip中的内容。

基本上你只需要在/firefox/src/extension/文件夹中添加所有内容。在Windows上我也添加了/firefox/prebuilt/Win32/Release/webdriver-firefox.dll,但我不确定是否需要。 (在Linux上,您可能需要添加适当的.so文件)。

答案 1 :(得分:1)

好的,我通过发现我通过macports安装的virtualenv“缺失”来解决它,

sudo ln -s `which virtualenv-2.6` /opt/local/bin/virtualenv 

然后运行rake firefox,最后运行rake firefox_xpi ...

答案 2 :(得分:0)

以下代码在做什么?

from selenium.firefox.webdriver import WebDriver
d = WebDriver()

正确的webdriver导入和firefox实例化如下所示:

from selenium import webdriver
d = webdriver.Firefox()