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.

86 lines
3.1 KiB

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 加载完成
# 输入用户名
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 页面
# 点击“媒体库”
print("点击媒体库...")
media_library = page.get_by_text("媒体库") # 通过 text 定位媒体库
media_library.click()
# 点击“上传”按钮
print("点击上传按钮...")
upload_button = page.get_by_text("上传") # 通过 text 定位上传按钮
upload_button.click()
print("触发文件选择对话框...")
with page.expect_file_chooser() as fc_info:
page.locator("img").click() # 触发文件选择对话框
file_chooser = fc_info.value
file_chooser.set_files(r"d:\1.mp4") # 设置文件路径
# 检查上传成功状态
print("检查上传成功状态...")
while True:
success_message = page.locator("span:has-text('上传素材成功')") # 定位成功消息
if success_message.is_visible(): # 如果成功消息可见,表示上传成功
print("上传成功!")
break
print("上传进行中...")
time.sleep(0.5) # 每隔 0.5 秒检查一次
# 定位并点击包含“我的素材”的 <div> 元素
print("定位并点击包含“我的素材”的 <div> 元素...")
my_material_div = page.locator("div.mat-tab-label-content:has-text('我的素材')") # 定位 <div> 元素
my_material_div.click() # 点击该元素
time.sleep(1)
time.sleep(10)
except Exception as e:
print(f"操作过程中发生错误: {e}")
finally:
# 关闭浏览器
print("操作完成,关闭浏览器...")
context.close()
browser.close()
# 初始化 Playwright
playwright = sync_playwright().start()
# 运行测试
run(playwright)
# 结束 Playwright
playwright.stop()