webDriver的安裝步驟和使用說明(已chrome爲例)

1.查看自己chrome的版本

2.下載瀏覽器版本對應的chromeDrive

chrom驅動下載地址:http://npm.taobao.org/mirrors/chromedriver/

--------------------------------------------------------------------------------------------------------------------------

Firefox驅動geckodriver 下載地址:https://github.com/mozilla/geckodriver/releases/

IE的驅動IEdriver下載地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

--------------------------------------------------------------------------------------------------------------------------

 

3.將下載好的chromeDriver解壓好複製到谷歌瀏覽器安裝目錄,將谷歌瀏覽器安裝路徑添加環境變量中

3.安裝pycharm,安裝方法參考:

https://www.runoob.com/w3cnote/pycharm-windows-install.html

4.打開pycharm 使用pip下載selenium模塊

 pip install -U selenium

 

5.新建一個python文件,開始編寫測試腳本

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support.select import Select
import time


# 打開瀏覽器,且打開xxxx頁面
url = 'http://xxxxx'
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
driver.get(url)

#延時2秒
time.sleep(2)

# 通過id定位xx按鈕,點擊
driver.find_element_by_class_name("xx按鈕的類名").click()

#延時2秒
time.sleep(2)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章