const automator = require('miniprogram-automator'); (async () => { console.log('连接...'); const mp = await automator.connect({ wsEndpoint: 'ws://127.0.0.1:9420' }); await mp.switchTab('/pages/index/index'); await new Promise(r => setTimeout(r, 5000)); const page = await mp.currentPage(); console.log('page:', page.path); // Test 1: Get all views console.log('\n--- Test 1: All views ---'); const allViews = await page.$$('view'); console.log('view count:', allViews.length); // Test 2: Get text from first 20 views for (let i = 0; i < Math.min(allViews.length, 20); i++) { try { const text = (await allViews[i].textContent()).trim().replace(/\s+/g, ' '); if (text.length > 0) console.log(' view[' + i + ']:', text.substring(0, 60)); } catch {} } // Test 3: Get all text elements console.log('\n--- Test 2: All text ---'); const allTexts = await page.$$('text'); console.log('text count:', allTexts.length); for (let i = 0; i < Math.min(allTexts.length, 30); i++) { try { const text = (await allTexts[i].textContent()).trim(); if (text.length > 0) console.log(' text[' + i + ']:', text.substring(0, 60)); } catch {} } // Test 4: Try waitFor console.log('\n--- Test 3: waitFor ---'); try { await page.waitFor('.index-page', { timeout: 3000 }); console.log('.index-page: found'); } catch (e) { console.log('.index-page:', e.message); } // Test 5: Try getElementByXpath or other methods console.log('\n--- Test 4: Page data ---'); const data = await page.data(); console.log('data:', JSON.stringify(data).substring(0, 300)); mp.disconnect(); })().catch(e => console.error('Error:', e.message));