import sys
sys.stdout.reconfigure(encoding='utf-8')
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9224')
    page = browser.contexts[0].pages[0]
    
    confirm_el = page.locator("span:has-text('Confirm')").first
    box = confirm_el.bounding_box()
    print('Confirm box:', box)
    if box:
        page.mouse.click(box['x'] + box['width']/2, box['y'] + box['height']/2)
        page.wait_for_timeout(3000)
        page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\after_confirm_box.png')
        print('Clicked exact center!')
    else:
        print('Confirm button box not found')
