前面说过,selenium支持多种浏览器,因此只须要下载对应的浏览器驱动,将解压获得的exe文件放到python的安装目录下便可;html
各个浏览器驱动下载地址(较慢不推荐):http://www.seleniumhq.org/download/python
驱动下载地址:
Chrome驱动器下载: https://sites.google.com/a/chromium.org/chromedriver/downloads
放到chrome的安装目录下...\Google\Chrome\Application\ ,而后设置path环境变量
Edge驱动器下载: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox驱动器下载: https://github.com/mozilla/geckodriver/releases
放到chrome的安装目录下Firefox所在的安装路径,个人是"E:\Mozilla Firefox\",设置path环境变量
Path:E:\Mozilla Firefox\;
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/git
ie驱动器下载:http://www.pc6.com/softview/SoftView_435420.htmlgithub
验证seleniumweb
1.确保电脑上安装了Firefox浏览器chrome
2.cmd窗口输入以下指令浏览器
pythonui
from selenium import webdrivergoogle
webdriver.Firefox()url
webdriver.Chrome()
webdriver.Ie()
3.若是能启动浏览器,说明环境安装OK。
注意:若用Firefox浏览器,只能用46及46如下的版本(selenium2不兼容47以上)
selenium IDE安装
http://blog.csdn.net/echizen_520/article/details/65444396
配置驱动环境变量(path)
查看驱动浏览器实例:
#coding=utf-8
from selenium import webdriver
import unittest
class VisitGGByIE(unittest.TestCase):
def setUp(self):# unittest包的方法前面小写+后面单词Up首字母大写
#启动ie浏览器
self.driver=webdriver.Ie(executable_path="D:\\Python27\\chromedriver")#注意后面不加.exe
def test_visitGG(self):
#访问搜索首页
self.driver.get("https://97gg.net")
#打印当前网页的网址
print self.driver.current_url
#退出ie浏览器
def tearDown(self):
self.driver.quit()
#pass
if __name__=="__main__":
unittest.main()