Selenium環境搭建
最近幾天, 天天裝軟體, 搭建環境, 尤其是這個Selenium(瀏覽器自動化測試框架), 搭建環境時問百度谷歌, 搜到的都寫的含糊不清, 當然也可能我不是做測試的不能理解, 或者軟體版本不一致, 又或者是椅子太硬坐的不舒服. 於是就在此記錄下Selenium環境的搭建. 由於我不是做測試的, 具體學習可以參考文末的兩個連結.
還有, 人生苦短, 我用Python!!!
我搭建時所用的軟體及版本:
Ptyhon: 3.7.3
pip :19.0.3 (新版的Python安裝後自帶)
selenium-server-standalone: 3.141.59
Jdk: 8u201
Chrome: 73
Chrome驅動: 73.0.3683.68
Selenium 服務端安裝
-
安裝python3.x , 地址: https://www.python.org/
image
- 安裝pip (python的包管理工具, 新版python安裝後應該自帶pip, 可以在終端輸入 pip --version檢視)
image
-
通過pip install selenium安裝selenium

image
-
下載jdk並安裝, 下載地址: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
image
-
下載 selenium-server-standalone-3.xxx.xx.jar, 下載地址: https://www.seleniumhq.org/download/
image
-
java -jar selenium-server-standalone-3.xxx.xx.jar啟動這個jar包
-
根據自己的系統和Chrome版本下載對應的Chrome驅動(大版本一致即可), 下載地址: https://chromedriver.storage.googleapis.com/index.html , 下載後解壓是個可執行檔案, 放到python的安裝目錄下即可
image
Selenium客戶端安裝(前三步就是服務端安裝的前三步)
-
安裝python3.x , 地址: https://www.python.org/
image
- 安裝pip (python的包管理工具, 新版python安裝後應該自帶pip, 可以在終端輸入 pip --version檢視)
image
-
通過pip install selenium安裝selenium

image
- 新建一個python檔案, 如selenium-demo.py
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities driver = webdriver.Remote( command_executor='http://172.16.40.208:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME) driver.get("http://baidu.com")
注意: 此地址需要改為你自己的服務端的ip

image
- 開啟終端, 執行
py selenium-demo.py
安裝服務端的電腦會開啟Chrome瀏覽器, 並開啟百度首頁
Selenium IDE
- 此工具可輸入網址進行操作錄製
- 下載: https://www.seleniumhq.org/selenium-ide/ 是瀏覽器外掛形式, 介面如下
image