针对当前项目编写一个测试脚本,自动完成建议模块界面新增操作,操作含文本录入、点击、下拉框选择(input下拉框,非select下拉框) 因当前无法绕过动态验证码,直接使用已有cookies import requests import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException wd = webdriver.Chrome() url = '链接' cookies = {'value':'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpbklkIjoic3lzX3VzZXI6MzczIiwicm4iOiIyTHRGUnNUbDZabU1wQXRNa2FUMHZKd21ZbkhsQTdaYSJ9.UxsokDy5RkhL0RVNiwbgWA8m_YxHNqFPeQlKAbb8Sxs','name':'heimdall_token'} wd.get(url) wd.add_cookie(cookie_dict=cookies) wd.maximize_window() wd.get(url) time.sleep(5) try: element = wd.find_element(By.CSS_SELECTOR, ".menu-wrapper:nth-child(8) .el-submenu__title > .menu-item").click() time.sleep(2) element = wd.find_element(By.CSS_SELECTOR, ".menu-wrapper:nth-child(8) .nest-menu:nth-child(1) #sub_menu_txt").click() time.sleep(3) element = wd.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/form/div/div[2]/div/div/button/span").click() time.sleep(1) element = wd.find_element(By.CSS_SELECTOR, ".is-required > .el-form-item__content > .el-input > .el-input__inner").click() time.sleep(1) element = wd.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[3]/div/div[2]/form/div[1]/div/div[1]/input").send_keys("UI自动化") time.sleep(1) element = wd.find_element(By.CSS_SELECTOR, ".el-form-item__content > .el-select .el-input__inner").click() time.sleep(2) ele = wd.find_elements(By.CSS_SELECTOR, "body > div.el-select-dropdown.el-popper > div.el-scrollbar > div.el-select-dropdown__wrap.el-scrollbar__wrap > ul > li:nth-child(1)") # for循环判断需要的元素在哪里,点击它 for ul in ele: if "检索项" in ul.text: print(ul) ul.click() break time.sleep(1) element = wd.find_element(By.CSS_SELECTOR, "#app > div > div.main-container.hasTagsView > section > div > div:nth-child(4) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span").click() except NoSuchElementException as e: import traceback print('元素不存在') print(traceback.format_exc()) time.sleep(3) wd.quit()
第一个UI自动化脚本
于 2024-04-19 15:36:17 首次发布