1. 下载geckodriverckod
从selenium3开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而之前是executable_path="wires"。所有需要下载geckodriver。
1、下载 geckodriverckod 地址: https://github.com/mozilla/geckodriver/releases
2、解压后将geckodriverckod可以存放在任意路径,在使用webdriver时指明路径就行。
例如:
将geckodriverckod放在/usr/local/bin/下,
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco }
span.s1 { color: #00b400 }
span.s2 { text-decoration: underline; color: #00b400 }
driver = webdriver.Firefox(executable_path = "/usr/local/bin/geckodriver")
如果没有下载geckodriverckod或是没有指明geckodriverckod的路径,执行执行程序会报错,如下:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #ff2600 }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; color: #0080e1 }
span.s1 { color: #ff2600 }
span.s2 { text-decoration: underline }
Traceback (most recent call last):
File "/Users/evan/evan/Eclipse/Selenium/src/Selenium_learn/learn_1.py", line 14, in <module>
driver = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 144, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH.