You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
64 lines
2.2 KiB
5 months ago
|
import time
|
||
|
from playwright.sync_api import Playwright, sync_playwright
|
||
|
|
||
|
def run(playwright: Playwright) -> None:
|
||
|
# 启动浏览器,禁用无头模式
|
||
|
browser = playwright.chromium.launch(headless=False)
|
||
|
context = browser.new_context()
|
||
|
page = context.new_page()
|
||
|
|
||
|
try:
|
||
|
# 打开登录页面
|
||
|
print("打开登录页面...")
|
||
|
page.goto("https://ww1.colorlightcloud.com/login", wait_until="domcontentloaded") # 等待 DOM 加载完成
|
||
|
time.sleep(2) # 等待 2 秒,确保页面完全加载
|
||
|
|
||
|
# 输入用户名
|
||
|
print("输入用户名...")
|
||
|
username_input = page.locator("#mat-input-0") # 通过 id 定位用户名输入框
|
||
|
username_input.fill("Ylt5786")
|
||
|
|
||
|
# 输入密码
|
||
|
print("输入密码...")
|
||
|
password_input = page.locator("input[type='password']") # 根据实际元素定位密码输入框
|
||
|
password_input.fill("DJCtjy064")
|
||
|
|
||
|
# 点击登录按钮
|
||
|
print("点击登录按钮...")
|
||
|
login_button = page.locator("button.color-login-btn") # 通过 class 定位登录按钮
|
||
|
login_button.click()
|
||
|
|
||
|
# 等待登录成功
|
||
|
print("等待登录成功...")
|
||
|
page.wait_for_url("https://ww1.colorlightcloud.com/home", timeout=60000) # 等待跳转到 home 页面
|
||
|
time.sleep(2) # 等待 2 秒,确保页面完全加载
|
||
|
|
||
|
# 点击“媒体库”
|
||
|
print("点击媒体库...")
|
||
|
media_library = page.get_by_text("媒体库") # 通过 text 定位媒体库
|
||
|
media_library.click()
|
||
|
time.sleep(2) # 等待 2 秒,确保页面完全加载
|
||
|
|
||
|
# 点击“上传”按钮
|
||
|
print("点击上传按钮...")
|
||
|
upload_button = page.get_by_text("上传") # 通过 text 定位上传按钮
|
||
|
upload_button.click()
|
||
|
|
||
|
except Exception as e:
|
||
|
print(f"操作过程中发生错误: {e}")
|
||
|
finally:
|
||
|
# 关闭浏览器
|
||
|
print("操作完成,关闭浏览器...")
|
||
|
|
||
|
time.sleep(60)
|
||
|
# context.close()
|
||
|
# browser.close()
|
||
|
|
||
|
# 初始化 Playwright
|
||
|
playwright = sync_playwright().start()
|
||
|
|
||
|
# 运行测试
|
||
|
run(playwright)
|
||
|
|
||
|
# 结束 Playwright
|
||
|
# playwright.stop()
|