import sys
from playwright.sync_api import sync_playwright

if hasattr(sys.stdout, 'reconfigure'):
    sys.stdout.reconfigure(encoding='utf-8')

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://127.0.0.1:9224')
    page = browser.contexts[0].pages[0]
    elements = page.locator('text=/300 WARSHIPS/i')
    print('Matching elements count:', elements.count())
    for i in range(elements.count()):
        el = elements.nth(i)
        tag = el.evaluate('e => e.tagName')
        visible = el.is_visible()
        text = el.inner_text()
        print(f'Element [{i}] tag: {tag}, visible: {visible}, text: {text[:100]}')
