#!/usr/bin/env python3 """ 调试页面元素 """ import sys sys.path.insert(0, ".") from src import WebTester def debug_page(): """调试页面元素""" tester = WebTester(model="glm", headless=False) try: # 启动浏览器 tester.start() tester.goto("http://47.99.105.253:8084") # 登录 print("登录中...") tester.test("填入账号admin 密码password,登录成功") # 等待页面加载 import time time.sleep(3) page = tester.browser.page # 检查侧边栏 print("\n=== 检查侧边栏元素 ===") # 查找所有侧边栏元素 sidebar_selectors = [ ".ant-layout-sider", "aside", ".sidebar", ".ant-menu" ] for sel in sidebar_selectors: count = page.locator(sel).count() print(f"{sel}: {count} 个元素") # 查找菜单项 print("\n=== 查找菜单项 ===") menu_texts = ["立项论证管理", "产品方案管理", "研制方案", "系统管理"] for text in menu_texts: # 尝试不同的定位器 locators = [ f"text={text}", f".ant-menu-item:has-text('{text}')", f"aside :has-text('{text}')", f"*:has-text('{text}')" ] print(f"\n查找: {text}") for loc_str in locators: try: loc = page.locator(loc_str) count = loc.count() visible = 0 for i in range(count): if loc.nth(i).is_visible(): visible += 1 print(f" {loc_str}: {count} 个元素, {visible} 个可见") except Exception as e: print(f" {loc_str}: 错误 - {e}") # 打印页面结构 print("\n=== 页面结构 ===") print(f"当前URL: {page.url}") print(f"页面标题: {page.title()}") finally: tester.stop() if __name__ == "__main__": debug_page()