import * as dotenv from 'dotenv'; import * as path from 'path'; dotenv.config({ path: path.resolve(__dirname, '../.env') }); import { createDriver } from '../drivers/factory'; const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); async function main() { const d: any = createDriver(); await d.createSession(); try { await d.goBackToHomepage(); await sleep(1500); await d.dismissPopupIfPresent(); const names = new Set(); for (let i = 0; i < 8; i++) { const src = await d.getSource(); for (const m of src.split('<')) { if (!/resource-id="[^"]*\/(nameText|nameTextMeter)"/.test(m)) continue; const t = (m.match(/text="([^"]*)"/) || [])[1]; if (t && t.trim()) names.add(t.trim()); } await d.scrollDown(500); await sleep(700); } console.log('首页设备:', [...names].join(' | ')); } finally { await d.destroySession(); } } main().catch(e => { console.error('ERR', e.message); process.exit(1); });