selenium(11)-web UI自动化实战
【禅道中的1个页面举例】
当然首先是需要搭建禅道的,搭建禅道的方法和步骤可以看我的另外一篇博客
https://www.cnblogs.com/xinhua19/p/13151296.html
【实战的页面】
禅道中的测试-套件页面
【代码思路】
- 登录后定位到测试界面
- 定位到套件页面
- 等待元素显示后,点击建套件
- 必填项输入,保存
【代码】
1 import time 2 3 from selenium import webdriver 4 from selenium.webdriver.common.by import By 5 from selenium.webdriver.support.wait import WebDriverWait 6 from selenium.webdriver.support import expected_conditions as EC 7 8 driver = webdriver.Chrome(r"H:\CCI\brm-test\drivers\chromedriver.exe") 9 driver.get("http://xxxxx:9001/zentao/") 10 # 登录成功 11 username = driver.find_element_by_id("account") 12 username.send_keys("admin") 13 14 password = driver.find_element_by_name("password") 15 password.send_keys("123456") 16 17 login = driver.find_element_by_id("submit") 18 login.click() 19 driver.implicitly_wait(5) 20 # 切换到测试界面 21 icon_test_page = driver.find_element_by_css_selector("#navbar > ul > li:nth-child(4) > a").click() 22 23 # 点击套件 24 icon_test_taojian = driver.find_element_by_xpath('//*[@id="subNavbar"]/ul/li[5]/a').click() 25 26 27 icon_add_taojian = driver.find_element_by_css_selector( 28 "#mainContent > div > p > a" 29 ).click() 30 31 WebDriverWait(driver, 10, 1).until(EC.presence_of_element_located((By.ID, "name"))) 32 33 input_name = driver.find_element_by_id("name").send_keys("test") 34 icon_submit = driver.find_element_by_id("submit").click() 35 time.sleep(2) 36 driver.quit()