38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from playwright.sync_api import sync_playwright
|
|
import time
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=False) # 非无头模式,以便查看
|
|
page = browser.new_page()
|
|
|
|
# 访问登录页面
|
|
page.goto('http://localhost:5176/')
|
|
page.wait_for_load_state('networkidle')
|
|
|
|
# 等待验证码加载
|
|
time.sleep(2)
|
|
|
|
# 检查验证码图片是否存在
|
|
captcha_image = page.locator('img[alt="验证码"]')
|
|
if captcha_image.is_visible():
|
|
print("验证码图片已显示")
|
|
# 截图保存
|
|
page.screenshot(path='captcha-test.png')
|
|
print("已保存验证码截图到 captcha-test.png")
|
|
else:
|
|
print("验证码图片未显示")
|
|
|
|
# 检查控制台日志
|
|
print("\n控制台日志:")
|
|
for entry in page.context.logs():
|
|
print(f"{entry.type}: {entry.text}")
|
|
|
|
# 检查网络请求
|
|
print("\n网络请求:")
|
|
for request in page.context.requests():
|
|
if "captcha" in request.url:
|
|
print(f"验证码请求: {request.url}")
|
|
print(f"状态码: {request.response().status if request.response() else '无响应'}")
|
|
|
|
browser.close()
|