debug_after_click.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """Debug: after clicking the login button, observe what actually happens.
  2. Three things to check:
  3. 1. Did the URL change (login button actually triggered a state change)?
  4. 2. Are there any error messages visible (form validation failed)?
  5. 3. What geetest-related elements are present (correct class names)?
  6. """
  7. import asyncio
  8. import sys
  9. from pathlib import Path
  10. _HERE = Path(__file__).resolve().parent
  11. sys.path.insert(0, str(_HERE.parent / "src"))
  12. from playwright.async_api import async_playwright
  13. EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  14. URL = "https://pc.hzwlan.com/login/account"
  15. async def main():
  16. out = _HERE / "jfbym_diag"
  17. async with async_playwright() as p:
  18. browser = await p.chromium.launch(executable_path=EDGE, headless=True)
  19. ctx = await browser.new_context(viewport={"width": 1366, "height": 768})
  20. page = await ctx.new_page()
  21. await page.goto(URL, wait_until="networkidle", timeout=30000)
  22. await page.fill("input#username", "longwu988")
  23. await page.fill("input#password", "Longwu1988")
  24. btn = page.locator("button.login-form_box__submit_button").first
  25. await btn.click(force=True)
  26. # Give the page time to react (geetest async-load, or error to render)
  27. await page.wait_for_timeout(5000)
  28. await page.screenshot(path=str(out / "a1_after_click.png"), full_page=True)
  29. info = await page.evaluate("""() => {
  30. return {
  31. url: location.href,
  32. title: document.title,
  33. errors: [...document.querySelectorAll(
  34. '.ant-form-item-explain-error, .ant-message-error, .error-msg, [class*=error]'
  35. )].map(e => ({cls: e.className, text: (e.innerText||'').trim().slice(0,80)})),
  36. geetest_any: !!document.querySelector('[class*=geetest], iframe[src*=geetest]'),
  37. geetest_els: [...document.querySelectorAll(
  38. '[class*=geetest]'
  39. )].slice(0, 10).map(e => ({tag:e.tagName, cls:e.className.slice(0,60)})),
  40. captcha: !!document.querySelector('.geetest_captcha, .geetest_captcha_refresh'),
  41. iframes: [...document.querySelectorAll('iframe')].map(i => i.src.slice(0, 80)),
  42. };
  43. }""")
  44. print(f"url after click: {info['url']}")
  45. print(f"title: {info['title']}")
  46. print(f"geetest_any: {info['geetest_any']}")
  47. print(f"geetest_els: {info['geetest_els']}")
  48. print(f"captcha: {info['captcha']}")
  49. print(f"errors ({len(info['errors'])}): {info['errors']}")
  50. print(f"iframes: {info['iframes']}")
  51. await browser.close()
  52. print(f"\nscreenshot: {out / 'a1_after_click.png'}")
  53. asyncio.run(main())