3

Hi I just downloaded and installed selenium but, I can't figure out how to get it working I am using the following example as a test....

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()         #this is where I hit the error
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()

I do not have firefox installed on my computer is this why it is giving me an error? this is the error output I get when I try and run it

Traceback (most recent call last):
  File "C:/Python27/test/helloworld.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 60, in __init__
    self.binary, timeout),
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
    env=self._firefox_env).communicate()
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
    startupinfo)
WindowsError: [Error 87] The parameter is incorrect
4

1 回答 1

3

以下行启动 Firefox 浏览器,所以是的,它需要安装 Firefox。

driver = webdriver.Firefox()  

如果您没有安装 Firefox,您可以使用不同的浏览器:

webdriver.Opera
webdriver.Ie
webdriver.Chrome
...

help(webdriver)
于 2013-09-05T20:43:37.073 回答