|
|
|
@ -16,6 +16,11 @@ PREFIX_NAME = 'Test'
|
|
|
|
|
VIDEO_PATH = r"d:\1.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 等待
|
|
|
|
|
def wait(seconds=0.5):
|
|
|
|
|
time.sleep(seconds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 登录
|
|
|
|
|
def login(page):
|
|
|
|
|
# 打开登录页面
|
|
|
|
@ -50,7 +55,8 @@ def delProgram(page, keyword):
|
|
|
|
|
print(f"Found element with text: {text}")
|
|
|
|
|
# 点击
|
|
|
|
|
divs.nth(index).click()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 点击删除按钮
|
|
|
|
|
delete_icon = page.locator("mat-icon:has-text('delete')").nth(0)
|
|
|
|
|
if delete_icon.is_visible():
|
|
|
|
@ -60,7 +66,8 @@ def delProgram(page, keyword):
|
|
|
|
|
if confirm_button.is_visible():
|
|
|
|
|
confirm_button.click() # 点击该元素
|
|
|
|
|
cnt = cnt + 1
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
if cnt > 0:
|
|
|
|
|
print("删除" + str(cnt) + "个节目")
|
|
|
|
|
else:
|
|
|
|
@ -77,13 +84,15 @@ def delMaterial(page):
|
|
|
|
|
# 点击 MATERIAL_FOLDER_NAME
|
|
|
|
|
playback_charge_status = page.get_by_text(MATERIAL_FOLDER_NAME)
|
|
|
|
|
playback_charge_status.dblclick()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 检查 <span> 元素是否存在
|
|
|
|
|
if page.locator("span.media-group-name").count() > 0:
|
|
|
|
|
# 鼠标移动到第一个 <span> 元素
|
|
|
|
|
first_span = page.locator("span.media-group-name").nth(0) # 定位第一个 <span> 元素
|
|
|
|
|
first_span.hover() # 鼠标移动到该元素
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 定位并点击外层的 <span> 元素
|
|
|
|
|
checkbox_span = page.locator("span.mat-checkbox-inner-container").nth(0) # 定位 <span> 元素
|
|
|
|
|
if checkbox_span.is_visible():
|
|
|
|
@ -96,7 +105,8 @@ def delMaterial(page):
|
|
|
|
|
confirm_button = page.locator("button:has-text('确定')")
|
|
|
|
|
if confirm_button.is_visible():
|
|
|
|
|
confirm_button.click() # 点击该元素
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
print("删除素材完成!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -130,7 +140,8 @@ def uploadVideo(page, video_path):
|
|
|
|
|
print("上传成功!")
|
|
|
|
|
break
|
|
|
|
|
print("上传进行中...")
|
|
|
|
|
time.sleep(0.5) # 每隔 0.5 秒检查一次
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 发布节目
|
|
|
|
@ -138,7 +149,8 @@ def publish(page):
|
|
|
|
|
print("点击编辑节目...")
|
|
|
|
|
jiemu_library = page.get_by_text("编辑节目") # 通过 text 定位编辑节目
|
|
|
|
|
jiemu_library.click()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
|
|
|
|
|
# 点击 MATERIAL_FOLDER_NAME
|
|
|
|
|
print("点击" + MATERIAL_FOLDER_NAME + "...")
|
|
|
|
@ -183,7 +195,8 @@ def publish(page):
|
|
|
|
|
publish_button = page.locator("div.btn.publish") # 定位 <div> 元素
|
|
|
|
|
if publish_button.is_visible():
|
|
|
|
|
publish_button.click() # 点击该元素
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
tree_node = page.locator("mat-tree-node.node-custom-style", has_text="充电站")
|
|
|
|
|
# 点击 <mat-tree-node> 元素
|
|
|
|
|
if tree_node.count() > 0: # 确保元素存在
|
|
|
|
@ -209,7 +222,8 @@ def changeJieMu(page):
|
|
|
|
|
print("点击节目...")
|
|
|
|
|
program_library = page.get_by_text("节目").nth(0) # 通过 text 定位媒体库
|
|
|
|
|
program_library.click()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 排程
|
|
|
|
@ -217,7 +231,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
pc_library = page.get_by_text("排程").nth(0)
|
|
|
|
|
pc_library.click()
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 定位目标 <mat-icon> 元素
|
|
|
|
|
add_icon = page.locator("mat-icon", has_text="add").nth(1)
|
|
|
|
|
|
|
|
|
@ -230,7 +245,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
# 点击 <span> 元素
|
|
|
|
|
if broadcast_span.count() > 0: # 确保元素存在
|
|
|
|
|
broadcast_span.click()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 定位目标滑动开关的“滑块”部分
|
|
|
|
|
toggle_thumb = page.locator("div.mat-slide-toggle-thumb").nth(0)
|
|
|
|
|
# 点击“滑块”部分
|
|
|
|
@ -239,7 +255,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
# + 号
|
|
|
|
|
add_icon = page.locator("mat-icon", has_text="add").nth(2)
|
|
|
|
|
add_icon.click()
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
|
|
|
|
|
# 等待目标对话框出现
|
|
|
|
|
dialog = page.get_by_role('dialog', name='选择节目') # 通过对话框标题定位
|
|
|
|
@ -267,8 +284,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
span_handle = spans.nth(index).element_handle()
|
|
|
|
|
span_handle.evaluate("element => element.click()")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 定位目标 <input> 元素
|
|
|
|
|
input_element = page.locator("input#mat-input-3") # 通过 id 定位
|
|
|
|
|
input_element.click()
|
|
|
|
@ -282,7 +299,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
minute_input.fill("00") # 输入分钟
|
|
|
|
|
second_input.fill("00") # 输入秒
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
# 定位 <button> 元素
|
|
|
|
|
set_button = page.locator("button.owl-dt-control-button", has_text="Set")
|
|
|
|
|
set_button.click()
|
|
|
|
@ -292,7 +310,8 @@ def paiCheng(page, keyword):
|
|
|
|
|
# 点击 <input> 元素
|
|
|
|
|
time_input.click()
|
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
# 等待
|
|
|
|
|
wait()
|
|
|
|
|
hour_input = page.locator("input.owl-dt-timer-input").nth(0) # 第一个输入框(小时)
|
|
|
|
|
minute_input = page.locator("input.owl-dt-timer-input").nth(1) # 第二个输入框(分钟)
|
|
|
|
|
second_input = page.locator("input.owl-dt-timer-input").nth(2) # 第三个输入框(秒)
|
|
|
|
@ -304,6 +323,16 @@ def paiCheng(page, keyword):
|
|
|
|
|
set_button = page.locator("button.owl-dt-control-button", has_text="Set")
|
|
|
|
|
set_button.click()
|
|
|
|
|
|
|
|
|
|
# 定位目标 <span> 元素
|
|
|
|
|
confirm_span = page.locator("span.mat-button-wrapper", has_text="确认")
|
|
|
|
|
# 点击 <span> 元素
|
|
|
|
|
if confirm_span.count() > 0: # 确保元素存在
|
|
|
|
|
confirm_span.click()
|
|
|
|
|
print("Clicked on the confirm button.")
|
|
|
|
|
else:
|
|
|
|
|
print("Confirm button not found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(playwright: Playwright) -> None:
|
|
|
|
|
# 启动浏览器,禁用无头模式
|
|
|
|
|
browser = playwright.chromium.launch(headless=HEADLESS)
|
|
|
|
|