main
HuangHai 5 months ago
parent cb8be1d4d9
commit 7cf44e0153

@ -145,7 +145,7 @@ def uploadVideo(page, video_path):
# 发布节目
def publish(page):
def publish(page, title, width, height):
print("点击编辑节目...")
jiemu_library = page.get_by_text("编辑节目") # 通过 text 定位编辑节目
jiemu_library.click()
@ -165,55 +165,51 @@ def publish(page):
print("定位目标 <canvas> 元素...")
canvas_element = page.locator("canvas#proCanvas") # 定位 <canvas> 元素
wait()
# 执行拖动操作
print("执行拖动操作...")
img_element.drag_to(canvas_element) # 将图片拖动到 <canvas> 中
wait()
# 定位并输入文本
print("定位并输入文本...")
input_element = page.locator("input[formcontrolname='contentDisplayName']") # 定位 <input> 元素
if input_element.is_visible():
input_element.fill("Test1") # 输入文本
input_element.fill(title) # 输入文本
else:
print("<input> 元素未找到")
wait()
# 定位并输入数值
print("定位并输入数值...")
input_element = page.locator("input[formcontrolname='width']").nth(0) # 定位 <input> 元素
if input_element.is_visible():
input_element.fill("1280") # 输入数值
input_element.fill(width) # 输入数值
else:
print("<input> 元素未找到")
wait()
# 定位并输入数值
print("定位并输入数值...")
input_element = page.locator("input[formcontrolname='height']").nth(0) # 定位 <input> 元素
if input_element.is_visible():
input_element.fill("720") # 输入数值
input_element.fill(height) # 输入数值
else:
print("<input> 元素未找到")
wait()
# 定位并点击“发布”按钮
print("定位并点击“发布”按钮...")
publish_button = page.locator("div.btn.publish") # 定位 <div> 元素
if publish_button.is_visible():
publish_button.click() # 点击该元素
# 等待
wait()
wait(2)
tree_node = page.locator("mat-tree-node.node-custom-style", has_text="充电站")
# 点击 <mat-tree-node> 元素
if tree_node.count() > 0: # 确保元素存在
tree_node.click()
print("Clicked on the mat-tree-node.")
# 点击确定按钮
# 定位目标 <span> 元素
confirm_button = page.locator("span.mat-button-wrapper", has_text="确认")
# 点击 <span> 元素
if confirm_button.count() > 0: # 确保元素存在
confirm_button.click()
print("Clicked on the confirm button.")
else:
print("Confirm button not found.")
else:
print("mat-tree-node not found.")
tree_node.click()
# 点击确定按钮
# 定位目标 <span> 元素
confirm_button = page.locator("span.mat-button-wrapper", has_text="确认")
# 点击 <span> 元素
confirm_button.click()
# 切换到节目
@ -295,47 +291,60 @@ def paiCheng(page, keyword, stHour, stMin, stSec, endHour, endMin, endSec):
# 定位目标 <input> 元素
input_element = page.locator("input#mat-input-3") # 通过 id 定位
input_element.click()
wait()
# 定位目标 <input> 元素
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) # 第三个输入框(秒)
wait()
# 输入时间
hour_input.fill(stHour) # 输入小时
wait()
minute_input.fill(stMin) # 输入分钟
wait()
second_input.fill(stSec) # 输入秒
# 等待
wait()
# 定位 <button> 元素
set_button = page.locator("button.owl-dt-control-button", has_text="Set")
set_button.click()
wait()
# 定位目标 <input> 元素
time_input = page.locator("input#mat-input-4") # 通过 id 定位
# 点击 <input> 元素
time_input.click()
# 等待
wait()
hour_input = page.locator("input.owl-dt-timer-input").nth(0) # 第一个输入框(小时)
wait()
minute_input = page.locator("input.owl-dt-timer-input").nth(1) # 第二个输入框(分钟)
wait()
second_input = page.locator("input.owl-dt-timer-input").nth(2) # 第三个输入框(秒)
wait()
# 输入时间
hour_input.fill(endHour) # 输入小时
wait()
minute_input.fill(endMin) # 输入分钟
wait()
second_input.fill(endSec) # 输入秒
wait()
# 定位 <button> 元素
set_button = page.locator("button.owl-dt-control-button", has_text="Set")
set_button.click()
wait()
# 定位目标 <span> 元素
confirm_span = page.locator("span.mat-button-wrapper", has_text="确认")
# 点击 <span> 元素
confirm_span.click()
wait()
# 定位目标 <span> 元素
apply_span = page.locator("span", has_text="应用").nth(0)
apply_span.click()
wait()
def run(playwright: Playwright) -> None:
@ -358,7 +367,7 @@ def run(playwright: Playwright) -> None:
uploadVideo(page, VIDEO_PATH)
# 发布节目
publish(page)
publish(page, 'Test1', str(1280), str(720))
# 切换到节目
changeJieMu(page)

Loading…
Cancel
Save