Selenium与Python在Snow Leopard上
我正在尝试在Snow Leopard上使用自带的Python(2.6.1)和Selenium。因为我对Python还很陌生,所以我有点搞不清楚自己哪里出错了,因为在我的Ubuntu系统上,完全一样的操作是可以正常工作的:
- 用命令“sudo easy_install -U selenium”安装Selenium
- 用Firefox的Selenium界面创建一个简单的测试,并把它导出为Python WebDriver(命名为mytest.py)
- 然后运行命令“$ 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
2 个回答
0
我对Selenium一无所知,但错误信息显示它找不到Firefox的可用路径。
你需要修改它的配置文件,让它知道Firefox的可执行文件在哪里。
现在的配置文件可能是默认设置,指向Linux系统上Firefox的安装位置(所以在Ubuntu上能用)。但是在Mac系统上,这个位置可能就不对了。
7
首先检查一下你的Firefox程序的位置。它是不是放在这个地方:/Applications/Firefox.app/Contents/MacOS/firefox?
想了解更多信息,可以查看这个页面:http://code.google.com/p/selenium/wiki/FirefoxDriver