Snow Leopard 上的 Selenium 和 Python

发布于 2024-12-19 01:47:09 字数 2694 浏览 0 评论 0原文

我正在尝试在 Snow Leopard 上使用带有 Selenium 的库存 Python (2.6.1)。作为 Python 的新手,我对自己做错的事情感到有点茫然,因为这个完全相同的过程在我的 ubuntu 机器上运行得很好:

  1. sudo easy_install -U selenium
  2. 使用 Firefox Selenium UI 创建一个简单的测试,并将其导出为 Python WebDriver (as mytest.py)
  3. $ python mytest.py (这会导致:

此错误消息:

E

======================================================================
ERROR: test_mytest_py (__main__.MytestPy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mytest.py", line 8, in setUp
    self.driver = webdriver.Firefox()
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 45, in __init__
    self.binary, timeout),
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 41, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in _start_from_profile_path
    Popen([self._start_cmd, "-silent"], stdout=PIPE, stderr=PIPE).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 595, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1106, in _execute_child
OSError: [Errno 2] No such file or directory

----------------------------------------------------------------------
Ran 1 test in 0.302s

FAILED (errors=1)

值得注意的一件事是,当我运行“sudo easy_install -U selenium”时,我确实收到警告:

$ sudo easy_install -U selenium
Searching for selenium
Reading http://pypi.python.org/simple/selenium/
Reading http://www.openqa.org/
Reading http://code.google.com/p/selenium/
Reading http://seleniumhq.org/
Best match: selenium 2.14.0
Downloading http://pypi.python.org/packages/source/s/selenium/selenium-2.14.0.tar.gz#md5=8de9ee26d699d699f846f14f9a184e60
Processing selenium-2.14.0.tar.gz
Running selenium-2.14.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-yQVlpa/selenium-2.14.0/egg-dist-tmp-svoAjf
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'src_root'
warning: no files found matching 'docs/api/py/index.rst'
Adding selenium 2.14.0 to easy-install.pth file

Installed /Library/Python/2.6/site-packages/selenium-2.14.0-py2.6.egg
Processing dependencies for selenium
Finished processing dependencies for selenium

I'm trying to use the stock Python (2.6.1) on Snow Leopard with Selenium. Being quite new to Python, I'm a at a bit of a loss for what I've done wrong, as this exact same process worked just fine on my ubuntu box:

  1. sudo easy_install -U selenium
  2. Create a simple test with Firefox Selenium UI, and export it as Python WebDriver (as mytest.py)
  3. $ python mytest.py (which results in:

This error message:

E

======================================================================
ERROR: test_mytest_py (__main__.MytestPy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mytest.py", line 8, in setUp
    self.driver = webdriver.Firefox()
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 45, in __init__
    self.binary, timeout),
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
    self.binary.launch_browser(self.profile)
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 41, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "/Library/Python/2.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in _start_from_profile_path
    Popen([self._start_cmd, "-silent"], stdout=PIPE, stderr=PIPE).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 595, in __init__
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1106, in _execute_child
OSError: [Errno 2] No such file or directory

----------------------------------------------------------------------
Ran 1 test in 0.302s

FAILED (errors=1)

One thing worth noting is that when I ran "sudo easy_install -U selenium", I did get a warning:

$ sudo easy_install -U selenium
Searching for selenium
Reading http://pypi.python.org/simple/selenium/
Reading http://www.openqa.org/
Reading http://code.google.com/p/selenium/
Reading http://seleniumhq.org/
Best match: selenium 2.14.0
Downloading http://pypi.python.org/packages/source/s/selenium/selenium-2.14.0.tar.gz#md5=8de9ee26d699d699f846f14f9a184e60
Processing selenium-2.14.0.tar.gz
Running selenium-2.14.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-yQVlpa/selenium-2.14.0/egg-dist-tmp-svoAjf
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'src_root'
warning: no files found matching 'docs/api/py/index.rst'
Adding selenium 2.14.0 to easy-install.pth file

Installed /Library/Python/2.6/site-packages/selenium-2.14.0-py2.6.egg
Processing dependencies for selenium
Finished processing dependencies for selenium

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哥,最终变帅啦 2024-12-26 01:47:09

首先检查您的 Firefox 二进制文件位置。它是否放置在此处:/Applications/Firefox.app/Contents/MacOS/firefox

有关详细信息,请查看此页面:http://code.google.com/p/selenium/wiki/FirefoxDriver

Check your Firefox binary location first. Does it placed at here: /Applications/Firefox.app/Contents/MacOS/firefox
?

For more information, please check this page: http://code.google.com/p/selenium/wiki/FirefoxDriver

避讳 2024-12-26 01:47:09

我对 Selenium 一无所知,但回溯表明它没有通往 Firefox 的可用路径。

您需要更改其配置/配置文件以为其提供 Firefox 可执行版本的路径。

目前的配置文件可能在 Linux 机器上具有 Firefox 的默认位置(这就是它在 Ubuntu 上运行的原因)。但在 OSX 上它不会位于这个位置。

I know nothing about Selenium but the traceback indicates that it doesn't have a usable path to Firefox.

You will need to change its configuration/profile file to give it a path to an executable version of Firefox.

The profile as it stands probably has the default location of Firefox on a linux box (hence why it works on Ubuntu). But it wont be at this location on OSX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文