利用python+selenium在pycharm下進行頁面登陸的半自動測試


很久沒有寫了,現在正式入職,准備好好干,加油!

我的第一個較正式的測試代碼:

from selenium import webdriver
import unittest
import sys
import importlib
import time
importlib.reload(sys)
#sys.setdefaultencoding('utf8')  python3不需要
class TestLogin(unittest.TestCase):
# 指定瀏覽器
def setUp(self):
self.driver = webdriver.Chrome()
# 打開url
self.driver.get("http://www.ibdata.cn/#/login")

# 登錄操作
def test_login(self):
username = "1111111"
password = "111111"
# 執行登錄操作
#用戶名的定位
self.driver.find_element_by_name("handle").clear()
self.driver.find_element_by_name("handle").send_keys(username)
time.sleep(2)
#密碼的定位
#因為所有元素的條件相同所以我在此選擇xpath進行定位
self.driver.find_elements_by_xpath("//input[@name='handle']")[-1].click()
self.driver.find_elements_by_xpath("//input[@name='handle']")[-1].send_keys(password)

# self.driver.find_element_by_name("handle").clear()
#self.driver.find_element_by_name("handle").send_keys(password)

# 點擊登錄
self.driver.find_element_by_class_name("sign-button").click()
time.sleep(5)

# 關閉瀏覽器
'''def tearDown(self):
self.driver.quit()'''


if __name__ == "__main__":
unittest.main()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM