日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

pythonui自动化测试脚本实战_Python UI自动化测试实战 Zero to Hero Se

發布時間:2024/7/23 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pythonui自动化测试脚本实战_Python UI自动化测试实战 Zero to Hero Se 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Selenium介紹

Selenium是用于測試Web應用程序的可移植框架。Selenium提供了一種回放工具,用于編寫功能測試,而無需學習測試腳本語言(Selenium IDE)。它還提供了一種特定于測試領域的語言(Selenese),可以用多種流行的編程語言編寫測試,包括C#,Groovy,Java,Perl,PHP,Python,Ruby和Scala。然后可以在大多數現代Web瀏覽器上運行測試。Selenium繼續 Windows,Linux和macOS。它是根據Apache License 2.0發布的開源軟件(引自維基百科)

2.Selenium的安裝

(yiluo) ? ~ pip install selenium

Collecting selenium

Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl

Requirement already satisfied: urllib3 in ./yiluo/lib/python3.7/site-packages (from selenium) (1.25.7)

Installing collected packages: selenium

Successfully installed selenium-3.141.0

3.安裝谷歌瀏覽器驅動

4.簡單的嘗試打開簡書

#!/usr/bin/python3

import time

from selenium import webdriver

driver = webdriver.Chrome()

driver.get('https://www.jianshu.com/u/3c9531339206')

time.sleep(3)

driver.close()

(yiluo) ? Code python web.py

自動打開的網頁

6.定位元素的一些方式

id

name

class name

tag name

link text

partial link text

xpath

css selector

7. Python webdriver 中的使用方法

find_element_by_id()

find_element_by_name()

find_element_by_class_name()

find_element_by_tag_name()

find_element_by_link_text()

find_element_by_partial_link_text()

find_element_by_xpath()

find_element_by_css_selector()

8.實例軟件測試網站Testerhome的登陸腳本

#!/usr/bin/python3

from selenium import webdriver

from time import sleep

driver = webdriver.Chrome()

driver.get("https://testerhome.com/")

# 放大窗口

driver.maximize_window()

sleep(3)

# 進入登陸頁面

driver.find_element_by_xpath('//*[@id="main-page"]/div[1]/nav/div/ul[1]/li[2]/a').click()

sleep(3)

# 輸入賬號

driver.find_element_by_id('user_login').send_keys('你的賬戶')

# 輸入密碼

driver.find_element_by_id('user_password').send_keys('你的密碼')

# 點擊登陸按鈕

driver.find_element_by_xpath('//*[@id="new_user"]/div[4]/input').click()

sleep(3)

# 關閉窗口

driver.close()

登陸成功

......待續

享受每一天,Just Enjoy !

關注公眾號獲取更多內容

總結

以上是生活随笔為你收集整理的pythonui自动化测试脚本实战_Python UI自动化测试实战 Zero to Hero Se的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。