上一篇:(四)selenium自动化测试之上传本地文件_要开朗的spookypop的博客-CSDN博客_selenium上传本地文件
先看下测试代码运行效果:
在做自动化测试时,测试框架设计很重要,测试代码写法也很多种。最简单的莫过于流水式的写法,比如一个简单的登录功能
- import time
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.chrome.service import Service as ChromeService
- from selenium.webdriver.support.relative_locator import locate_with
- from webdriver_manager.chrome import ChromeDriverManager
-
- service = ChromeService(executable_path=ChromeDriverManager().install())
- driver = webdriver.Chrome(service=service)
- driver.get('http://www.softwarebox.club/pages/OnlineTools/AutoLearn')
- driver.implicitly_wait(3)
- driver.maximize_window()
- driver.find_element(By.ID, 'username').send_keys('小明')
- driver.find_element(By.ID, 'password').send_keys('123456Xm')
- # 通过XPath定位登录按钮,并点击
- d