1.下载 geckodriver,
在哪下载,为什么下载,参考
http://selenium-python.readthedocs.io/installation.html 1.3Drivers.
2. 解压geckodriver,。添加环境变量:(为什么添加,同样参考上面的官方,我都是按照官方教程做的)
GECKODRIVER
E:\...\geckodriver-v0.15.0-win64
在path中添加:%GECKODRIVER%
3. 编写代码:以下是官方提供的一个打开浏览器,搜索 ,关闭的脚本,把这个脚本保存,起个名字:python_org_search.py
http://selenium-python.readthedocs.io/getting-started.html
from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.python.org") assert "Python" in driver.title elem = driver.find_element_by_name("q") elem.clear() elem.send_keys("pycon") elem.send_keys(Keys.RETURN) assert "No results found." not in driver.page_source driver.close()4.运行,在当前目录下打开命令行,运行python python_org_search.py
5.遇到这个问题:Missing 'marionetteProtocol' field in handshake,这个问题后来查了一下,是我的firefox版本太低了,我的是38.升级到48以后正常。