python selenium 模塊的安裝及使用

安裝

pip install selenium 或者到https://pypi.python.org/pypi/selenium 下載setup安裝包,以後進入目錄後運行python setup.py installhtml

官方文檔

官方文檔地址:http://selenium-python.readthedocs.io/installation.htmlpython

安裝驅動

須要下載相應瀏覽器的驅動,驅動下載地址:http://docs.seleniumhq.org/download/git

把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()

參考:github

http://www.javashuo.com/article/p-mipgjbyx-mb.html
http://blog.csdn.net/nhudx061/article/details/43601065/
http://selenium-python.readthedocs.io/installation.html
http://www.javashuo.com/article/p-sveyymlj-x.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/49568096web

相關文章
相關標籤/搜索