第一个UI自动化脚本

针对当前项目编写一个测试脚本,自动完成建议模块界面新增操作,操作含文本录入、点击、下拉框选择(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()
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值