【软件测试】“火焰杯”自动化测试第一题
1 from selenium import webdriver 2 from selenium.webdriver.common.action_chains import ActionChains 3 import time 4 import random 5 import base64 6 7 from selenium.webdriver.common.keys import Keys 8 9 driver = webdriver.Chrome() 10 11 def Login(): 12 # 打开网站 13 driver.get("http://litemall.hogwarts.ceshiren.com/vue/index.html#/login?redirect=user") 14 time.sleep(1) 15 # 填充用户名 16 driver.find_element_by_css_selector("#app > div.login.view-router > div.field_group > div:nth-child(1) > div.md_field_control > input[type=text]").send_keys("reliable") 17 time.sleep(1) 18 # 填充密码 19 driver.find_element_by_css_selector("#app > div.login.view-router > div.field_group > div:nth-child(2) > div.md_field_control > input[type=password]").send_keys("success01") 20 # 点击登录 21 driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/button').click() 22 time.sleep(1) 23 driver.find_element_by_css_selector("#app > div.van-hairline--top-bottom.van-tabbar.van-tabbar--fixed > div:nth-child(1) > div.van-tabbar-item__icon > i").click() 24 time.sleep(1) 25 driver.find_element_by_class_name('van-field__control').click() 26 time.sleep(1) 27 driver.find_element_by_class_name('van-field__control').send_keys("火焰杯测试商品") 28 time.sleep(1) 29 driver.find_element_by_class_name('van-field__control').send_keys(Keys.ENTER) 30 time.sleep(1) 31 #加入购物车 //*[@id="app"]/div[2]/div[2]/div[1]/div/div/div[1]/div 32 33 driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div[1]/div/div/div[1]/div').click() 34 time.sleep(1) 35 driver.find_element_by_xpath('// *[ @ id = "app"] / div[2] / div[5] / button[1]').click() 36 time.sleep(2) 37 driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[3]/div[3]/div[3]/button[1]').click() 38 time.sleep(2) 39 driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[5]/div[1]/div').click() 40 41 if __name__ == "__main__": 42 Login()
好看请赞,养成习惯:) 本文来自博客园,作者:靠谱杨, 转载请注明原文链接:https://www.cnblogs.com/rainbow-1/p/16265500.html
欢迎来我的51CTO博客主页踩一踩 我的51CTO博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地