目前第17定位发视频页面的发布按钮存在问题,有无好心人指导一下,html代码不太会
old_path = os.path.join(video_folder_path, f)
new_path = os.path.join(video_folder_path, new_name)
try:
os.rename(old_path, new_path) # 重命名文件
except FileExistsError:
print(f"文件 {new_name} 已存在,跳过重命名")
new_path = old_path # 如果文件已存在,使用原路径
video_files.append(new_path) # 添加到视频文件列表
# 14. 遍历每个视频文件进行上传
for video_file in video_files:
try:
# 15. 等待上传按钮出现
upload_button = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@type='file']"))
)
# 16. 上传视频文件
upload_button.send_keys(video_file)
print(f"正在上传: {video_file}")
except Exception as e:
print(f"上传视频 {os.path.basename(video_file)} 时出错: {e}")
driver.quit()
raise e
#17.定位发布按钮并点击
try:
WebDriverWait(driver, 180).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), '发布')]"))
).click()
print("点击发布按钮")
except Exception as e:
print(f"点击发布按钮时出错: {e}")
driver.quit()
raise e
# 18. 等待发布完成提示
try:
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.XPATH, "//*[contains(text(), '发布成功')]"))
)
print("发布成功")
except Exception as e:
print(f"等待发布完成提示时出错: {e}")
driver.quit()
raise e