liu
9 小时以前 514f372270b181f82e4deff98f8d0f38ace63183
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/** 袋码页结构诊断:登录后 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();
})();