# -*- coding: utf-8 -*-
# 导入包
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 执行程序
class UntitledTestCase(unittest.TestCase):
def setUp(self):
#打开浏览器
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
self.driver = webdriver.Chrome(options=options)
self.driver.implicitly_wait(10)
self.base_url = "https://www.google.com/"
def test_untitled_test_case(self):
driver = self.driver
# 注意要先打开网站页面
driver.get("https://www.aaa.com")
# 将登录的cookie导入页面
cookie = {'name': 'login', 'value': '77645a31f03ee8476a729b7f5524b9ad', 'domain': '.aaaaa.com'}
self.driver.add_cookie(cookie)
driver.get("https://www.你要登录的网站")
# 等待元素加载完成
# 进行测试动作
wait = WebDriverWait(driver, 10)
element = wait.until(
EC.element_to_be_clickable((By.XPATH, "")))
element.click()
element = wait.until(
EC.element_to_be_clickable((By.XPATH, "")))
element.click()
driver.get("https://agent.oceanengine.com/admin/download")
element = wait.until(EC.element_to_be_clickable(
(By.XPATH, "")))
element.click()
time.sleep(10)
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
python3自动测试程序,通过cookie跳过验证
最新推荐文章于 2023-10-22 12:44:06 发布