/** 袋码页结构诊断:登录后 dump 搜索项与工具栏按钮,用于校准测试选择器 */
|
const { chromium } = require('playwright');
|
|
const BASE = 'http://127.0.0.1:5666';
|
|
(async () => {
|
const browser = await chromium.launch({ headless: true });
|
const page = await browser.newPage({ viewport: { width: 1600, height: 900 } });
|
page.on('pageerror', (e) => console.log('pageerror:', e.message));
|
|
await page.goto(`${BASE}/auth/login`, { waitUntil: 'domcontentloaded' });
|
await page.locator('input[name=username]').waitFor({ timeout: 60_000 });
|
await page.locator('input[name=username]').fill('admin');
|
await page.locator('input[name=password]').fill('admin123');
|
await page.locator('button:has-text("登录")').last().click();
|
await page.waitForURL((u) => !u.pathname.includes('/auth/login'), { timeout: 60_000 });
|
console.log('登录后 URL:', page.url());
|
await page.waitForTimeout(3000);
|
|
console.log('\n--- 菜单项(含“袋码/赋码”的)---');
|
for (const el of await page.locator('a, span, div').all()) {
|
const t = (await el.innerText().catch(() => '')).trim();
|
if (t && t.length < 20 && /袋码|赋码|一袋一码/.test(t)) {
|
console.log(JSON.stringify(t));
|
}
|
}
|
|
for (const target of ['/bagcode/bag-code', '/bagcode', '/mes/pro/bagCode']) {
|
await page.goto(`${BASE}${target}`, { waitUntil: 'domcontentloaded' });
|
await page.waitForTimeout(4000);
|
const url = page.url();
|
const hasExport = (await page.getByRole('button', { name: '导出二维码' }).count()) > 0;
|
console.log(`\n>>> 尝试 ${target} → 实际 ${url},导出按钮数=${hasExport}`);
|
if (!hasExport) continue;
|
|
console.log('--- 搜索输入框 placeholder ---');
|
for (const el of await page.locator('input').all()) {
|
const ph = await el.getAttribute('placeholder');
|
if (ph && (await el.isVisible().catch(() => false))) console.log(JSON.stringify(ph));
|
}
|
console.log('--- 全部可见按钮文本 ---');
|
for (const el of await page.locator('button').all()) {
|
const t = (await el.innerText().catch(() => '')).trim();
|
if (t && (await el.isVisible().catch(() => false))) console.log(JSON.stringify(t));
|
}
|
break;
|
}
|
|
await browser.close();
|
})();
|