言簡意賅的說下Selenium是什麼html
Selenium是前臺測試框架,支持IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome等瀏覽器,我只試了這四個,別的你們用的時候能夠試下。python
用腳本能夠模擬網頁的點擊,輸入,提交,驗證等操做。git
可參照下列網站進行學習:github
1.https://selenium-python-zh.readthedocs.io/en/latest/installation.html(中文)web
2.https://selenium-python.readthedocs.io/index.html(英文)瀏覽器
安裝/運行Demo:框架
1.Python官方網站下載最新版Python學習
https://www.python.org/downloads/測試
2.經過pip下載安裝Selenium網站
也能夠直接進入Python的Scripts目錄,按住Shift+鼠標右鍵,選擇PowerShell窗口。
注意有提示升級Pip的時候根據命令升級你的PIP
D:\>cd D:\python\Scripts D:\python\Scripts>pip install selenium
3.查看Selenium版本
D:\python\Scripts>pip show selenium Name: selenium Version: 3.14.1 Summary: Python bindings for Selenium Home-page: https://github.com/SeleniumHQ/selenium/ Author: UNKNOWN Author-email: UNKNOWN License: Apache 2.0 Location: d:\python\lib\site-packages Requires: urllib3 Required-by: D:\python\Scripts>
4.下載火狐Firefox的驅動geckodriver 下載地址:https://github.com/mozilla/geckodriver/releases/
注意版本,下載完成後將geckodriver.exe放到Python的安裝目錄下。個人是D:\Python,而後將D:\Python添加到系統的環境變量中
5.編寫腳本
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
print (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()
6.運行Demo
D:\python>python 目錄\testPython.py
Welcome to Python.org
D:\python>
已上只是跑一個簡單的Demo,你們也能夠下載Selenium的IDE進行工做更方便。