const automator = require('miniprogram-automator'); (async () => { const mp = await automator.connect({ wsEndpoint: 'ws://127.0.0.1:9420' }); await mp.switchTab('/pages/index/index'); await new Promise(r => setTimeout(r, 2000)); const page = await mp.currentPage(); // $$ selector const titles = await page.$$('.section-title'); console.log('section-title count:', titles.length); for (let i = 0; i < titles.length; i++) { const text = await titles[i].textContent(); console.log(' title[' + i + ']:', text.trim()); } // $ single selector const hello = await page.$('.greeting-hello'); if (hello) { const text = await hello.textContent(); console.log('greeting:', text.trim()); } const gName = await page.$('.greeting-name'); if (gName) { const text = await gName.textContent(); console.log('name:', text.trim()); } const gDate = await page.$('.greeting-date'); if (gDate) { const text = await gDate.textContent(); console.log('date:', text.trim()); } // Health items const healthItems = await page.$$('.health-item'); console.log('health items:', healthItems.length); for (let i = 0; i < healthItems.length; i++) { const text = await healthItems[i].textContent(); console.log(' health[' + i + ']:', text.trim().replace(/\s+/g, ' ')); } // Service items const services = await page.$$('.service-item'); console.log('service items:', services.length); for (let i = 0; i < services.length; i++) { const text = await services[i].textContent(); console.log(' service[' + i + ']:', text.trim().replace(/\s+/g, ' ')); } // Empty state const empty = await page.$('.empty-text'); if (empty) { const text = await empty.textContent(); console.log('empty:', text.trim()); } // Empty hint const hint = await page.$('.empty-hint'); if (hint) { const text = await hint.textContent(); console.log('hint:', text.trim().replace(/\s+/g, ' ')); } await mp.close(); process.exit(0); })()