55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
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();
|
|
|
|
// Try $ selector (single element)
|
|
const title = await page.$('.section-title');
|
|
console.log('title element:', title ? 'found' : 'not found');
|
|
if (title) {
|
|
const text = await title.textContent();
|
|
console.log('title text:', text.trim());
|
|
}
|
|
|
|
// Try $$ selector (multiple)
|
|
const titles = await page.$$('.section-title');
|
|
console.log('titles count:', titles.length);
|
|
for (let i = 0; i < titles.length; i++) {
|
|
const text = await titles[i].textContent();
|
|
console.log(' title[' + i + ']:', text.trim());
|
|
}
|
|
|
|
// Check greeting
|
|
const hello = await page.$('.greeting-hello');
|
|
if (hello) console.log('greeting:', (await hello.textContent()).trim());
|
|
|
|
const name = await page.$('.greeting-name');
|
|
if (name) console.log('name:', (await name.textContent()).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, ' '));
|
|
}
|
|
|
|
// Check empty state
|
|
const empty = await page.$('.empty-text');
|
|
if (empty) console.log('empty text:', (await empty.textContent()).trim());
|
|
|
|
await mp.close();
|
|
process.exit(0);
|
|
})()
|