安装
pip install selenium
或者到https://pypi.python.org/pypi/selenium
下载setup安装包,之后进入目录后运行python setup.py install
官方文档
官方文档地址:http://selenium-python.readthedocs.io/installation.html
安装驱动
需要下载相应浏览器的驱动,驱动下载地址:http://docs.seleniumhq.org/download/
把geckodriver.exe放置到Python的目录,也把驱动放到Firefox的安装目录,并把Firefox的路径添加到系统环境变量path
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
参考:
https://www.cnblogs.com/gopythoner/p/7735379.html
http://blog.csdn.net/nhudx061/article/details/43601065/
http://selenium-python.readthedocs.io/installation.html
https://www.cnblogs.com/fnng/p/3325300.html
http://www.51testing.com/zhuanti/selenium.html
http://blog.csdn.net/blueheart20/article/details/70768930
https://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html
https://github.com/mozilla/geckodriver/releases
https://www.zhihu.com/question/49568096