您好我刚刚下载并安装了selenium但是,我无法弄清楚如何让它正常工作我使用以下示例作为测试....
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()
我的计算机上没有安装firefox,这就是为什么它给我一个错误? 这是我尝试运行时得到的错误输出
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
答案 0 :(得分:3)
以下行启动Firefox浏览器是的,它需要安装Firefox。
driver = webdriver.Firefox()
如果您没有安装Firefox,则可以使用不同的浏览器:
webdriver.Opera
webdriver.Ie
webdriver.Chrome
...
见
help(webdriver)