【软件测试】“火焰杯”自动化测试第一题
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博客
文章中的公众号名称可能有误,请统一搜索:靠谱杨的秘密基地
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具