80 lines
3.6 KiB
Python
80 lines
3.6 KiB
Python
from globals.driver_utils import init_appium_driver
|
||
from selenium.webdriver.support.ui import WebDriverWait
|
||
import permissions # 导入权限处理模块
|
||
import logging
|
||
from selenium.webdriver.common.by import By
|
||
from selenium.webdriver.support import expected_conditions as EC
|
||
import main # 导入权限处理模块
|
||
def get_breakpoint_list_from_page():
|
||
driver, wait = init_appium_driver("77a6ac91")
|
||
"""
|
||
从当前页面获取断点列表的断点名称
|
||
Returns:
|
||
list: 断点名称列表
|
||
"""
|
||
breakpoint_list = []
|
||
try:
|
||
# 优化点1: 等待列表容器出现,确保页面已加载
|
||
wait.until(EC.presence_of_element_located((By.ID, "com.bjjw.cjgc:id/upload_result_list")))
|
||
|
||
# 优化点2: 等待至少一个itemContainer出现,确保列表有数据
|
||
wait.until(EC.presence_of_element_located((By.ID, "com.bjjw.cjgc:id/itemContainer")))
|
||
|
||
# 方法1: 直接获取所有标题元素(最直接高效)
|
||
title_elements = driver.find_elements(By.ID, "com.bjjw.cjgc:id/title")
|
||
|
||
if title_elements:
|
||
for element in title_elements:
|
||
breakpoint_name = element.text
|
||
if breakpoint_name and breakpoint_name.strip(): # 增加空值过滤
|
||
breakpoint_list.append(breakpoint_name.strip())
|
||
print(f"✅ 直接通过title获取到 {len(breakpoint_list)} 个断点")
|
||
|
||
# 方法2: 如果方法1失败,通过itemContainer获取(备选方案)
|
||
if not breakpoint_list:
|
||
print("⚠️ 直接获取title失败,尝试通过itemContainer获取...")
|
||
item_containers = driver.find_elements(By.ID, "com.bjjw.cjgc:id/itemContainer")
|
||
for container in item_containers:
|
||
try:
|
||
title_element = container.find_element(By.ID, "com.bjjw.cjgc:id/title")
|
||
breakpoint_name = title_element.text
|
||
if breakpoint_name and breakpoint_name.strip():
|
||
breakpoint_list.append(breakpoint_name.strip())
|
||
except:
|
||
continue
|
||
print(f"✅ 通过itemContainer获取到 {len(breakpoint_list)} 个断点")
|
||
|
||
# 打印结果
|
||
if breakpoint_list:
|
||
print(f"📋 断点列表:")
|
||
for i, name in enumerate(breakpoint_list, 1):
|
||
print(f" {i}. {name}")
|
||
else:
|
||
print("⚠️ 未获取到任何断点,列表可能为空")
|
||
|
||
return breakpoint_list
|
||
|
||
except Exception as e:
|
||
print(f"❌ 获取断点列表失败: {str(e)}")
|
||
# 可以在这里打印更多调试信息
|
||
try:
|
||
page_source = driver.page_source
|
||
print("📄 当前页面源码已保存,可用于调试")
|
||
# 可以将page_source保存到文件,方便分析
|
||
with open("debug_page_source.xml", "w", encoding="utf-8") as f:
|
||
f.write(page_source)
|
||
except:
|
||
pass
|
||
return breakpoint_list
|
||
|
||
|
||
if __name__ == "__main__":
|
||
if permissions.grant_appium_permissions("77a6ac91"):
|
||
logging.info(f"设备 77a6ac91 权限授予成功")
|
||
else:
|
||
logging.warning(f"设备 77a6ac91 权限授予失败")
|
||
|
||
# 确保Appium服务器正在运行
|
||
main.ensure_appium_server_running(4723)
|
||
|
||
get_breakpoint_list_from_page() |