手把手教你搭建python+selenium自動化環(huán)境(圖文)
快速+簡單搭建環(huán)境。如果有問題,歡迎進(jìn)群討論留言。
第一步:安裝python解釋器
官網(wǎng)地址:https://www.python.org/
自動化測試最好下載3.7的。
下載完成后打開這個文件,然后傻瓜式安裝。
安裝好后,win+r打開命令行窗口,輸入python。如果顯示下圖,就說明安裝成功。
第二步:安裝pycharm編譯器。
傻瓜式安裝就可以了。
http://www.jetbrains.com/pycharm/download/#section=windows.
第三步:安裝selenium庫
pip install selenium
第四步:下載瀏覽器的驅(qū)動
我一般用的都是chrome比較具有代表性。
Chrome:
https://sites.google.com/a/chromium.org/chromedriver/downloads(需要翻墻)
Firefox:
https://github.com/mozilla/geckodriver/releases。
下載好后,將驅(qū)動放在python文件夾的scripts根目錄中。
第五步:打開pycharm寫第一個自動化demo驗證環(huán)境是否有問題
第一個demo
from selenium import webdriver import time import unittest class LoginPage(object): driver=webdriver.Firefox() driver.get("https://passport.hupu.com/pc/login?project=nba&from=pc") time.sleep(5) def test_login(self): self.driver.find_element_by_xpath("http://*[@id='J_username']").click() self.driver.find_element_by_xpath("http://*[@id='J_username']").clear() self.driver.find_element_by_xpath("http://*[@id='J_username']").send_keys("18777777777") self.driver.find_element_by_xpath("http://*[@id='J_pwd']").click() self.driver.find_element_by_xpath("http://*[@id='J_pwd']").clear() self.driver.find_element_by_xpath("http://*[@id='J_pwd']").send_keys("111111111") self.driver.find_element_by_xpath("http://*[@id='SM_BTN_1']/div[1]/div[4]").click() time.sleep(6) def test_threads(self): self.driver.get("https://bbs.hupu.com/hcbig") time.sleep(6) self.driver.find_element_by_id("g_n").click() time.sleep(6) self.driver.find_element_by_id("atc_title").click() self.driver.find_element_by_id("atc_title").clear() self.driver.find_element_by_id("atc_title").send_keys("橙子發(fā)的文字貼") self.driver.find_element_by_xpath("http://body").click() self.driver.find_element_by_xpath("http://body").send_keys("橙子使用自動化測試發(fā)的文字貼") self.driver.find_element_by_id("submitview").click() login=LoginPage() login.login() time.sleep(4) login.fatie_4524()
只要能啟動成功啟動瀏覽器,并且能看到鼠標(biāo)自動操作,就代表環(huán)境沒有問題了。
到此這篇關(guān)于手把手教你搭建python+selenium自動化環(huán)境(圖文)的文章就介紹到這了,更多相關(guān)python selenium自動化環(huán)境搭建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python+Selenium自動化環(huán)境搭建與操作基礎(chǔ)詳解
- Selenium+Python自動化腳本環(huán)境搭建的全過程
- 教你用Python+selenium搭建自動化測試環(huán)境
- selenium3.0+python之環(huán)境搭建的方法步驟
- selenium+python自動化測試之環(huán)境搭建
- selenium3+python3環(huán)境搭建教程圖解
- Python + selenium自動化環(huán)境搭建的完整步驟
- python+selenium開發(fā)環(huán)境搭建圖文教程
- Python語言中的Selenium環(huán)境搭建
相關(guān)文章
Python協(xié)程 yield與協(xié)程greenlet簡單用法示例
這篇文章主要介紹了Python協(xié)程 yield與協(xié)程greenlet簡單用法,簡要講述了協(xié)程的概念、原理,并結(jié)合實例形式分析了Python協(xié)程 yield與協(xié)程greenlet基本使用方法,需要的朋友可以參考下2019-11-11python3中利用filter函數(shù)輸出小于某個數(shù)的所有回文數(shù)實例
今天小編就為大家分享一篇 python3中利用filter函數(shù)輸出小于某個數(shù)的所有回文數(shù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11詳解Python中內(nèi)置的NotImplemented類型的用法
這篇文章主要介紹了詳解Python中內(nèi)置的NotImplemented類型的用法,包括對相關(guān)的__eq__()和__ne__()兩個方法使用的講解,需要的朋友可以參考下2015-03-03Python中斷言Assertion的一些改進(jìn)方案
python中的斷言Assertion使用起來很方便,但是也不盡如人意的地方,所以這篇文章通過幾個方面對Python中的斷言進(jìn)行了改進(jìn),感興趣的朋友們可以參考借鑒,下面來一起看看吧。2016-10-10Django中QuerySet查詢優(yōu)化之prefetch_related詳解
prefetch_related()和select_related()的設(shè)計目的很相似,都是為了減少SQL查詢的數(shù)量,但是實現(xiàn)的方式不一樣,下面這篇文章主要給大家介紹了關(guān)于Django中QuerySet查詢優(yōu)化之prefetch_related的相關(guān)資料,需要的朋友可以參考下2022-11-11