from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9222')
    page = browser.contexts[0].pages[0]
    
    # Click tab 'All' để về trang Posts chính
    print('Clicking All tab...')
    page.locator("a:has-text('All'), span:has-text('All')").first.click()
    page.wait_for_timeout(3000)
    
    # Tìm nút Edit profile
    print('Looking for Edit profile button...')
    edit_btn = page.locator("[aria-label*='Edit profile'], div[role='button']:has-text('Edit profile')").first
    print('Edit profile visible:', edit_btn.is_visible())
    edit_btn.click()
    page.wait_for_timeout(3000)
    
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\modal_opened.png')
    print('Screenshot saved!')
    browser.close()
