1. 程式人生 > 其它 >selenium實戰 登入後選單新增,檢視新增資料是不是第一條資料 (UI-0104)分享(白月黑羽網站selenium自動化學習)

selenium實戰 登入後選單新增,檢視新增資料是不是第一條資料 (UI-0104)分享(白月黑羽網站selenium自動化學習)

技術標籤:python

在這裡插入圖片描述

from selenium import webdriver
import  time
# 建立 Webwd 例項物件,指明使用chrome瀏覽器驅動
wd = webdriver.Chrome(r'D:\tools-work\chromedriver_win32\chromedriver.exe')

wd.implicitly_wait(5)#等待時間 一定要寫
# Webwd 例項物件的get方法 可以讓瀏覽器開啟指定網址
wd.get('http://127.0.0.1:8047/mgr/sign.html')
wd.find_element_by_id('username'
).send_keys("byhy") wd.find_element_by_id('password').send_keys("88888888") wd.find_element_by_tag_name('button').click() time.sleep(1) wd.find_element_by_xpath("//*[@class='fa fa-plus']").click()#找到藥品按鈕 # # # 點選添加藥品按鈕 一定要點選 也就是.click() wd.find_element_by_xpath("//*[@class='glyphicon glyphicon-plus']"
).click() # # # # # 插入3個數據,找到每一個可以輸入的地址 inputs = wd.find_elements_by_xpath("//*[@class='col-lg-8 col-md-8 col-sm-8']/div/*[1]") inputs[0].send_keys('青黴素軟膏') inputs[1].send_keys('YE-00001') inputs[2].send_keys('D1308批次2021') # #點選建立按鈕 wd.find_elements_by_xpath("//*[@class='btn btn-green btn-outlined btn-xs']"
)[0].click() time.sleep(1) titles = wd.find_elements_by_xpath("//*[@class='search-result-item'][1]/div/span[2]") texts = [f.text for f in titles] # print(texts) expected =['青黴素軟膏', 'YE-00001', 'D1308批次2021'] if texts == expected : print("------測試成功") else: print("===========測試失敗") wd.quit()