python selenium 模塊的安裝及使用


安裝

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM