import asyncio from playwright.async_api import async_playwright import os html_content = """
""" async def test_date(): with open("test.html", "w") as f: f.write(html_content) async with async_playwright() as p: browser = await p.chromium.launch(headless=True) page = await browser.new_page() await page.goto(f"file://{os.path.abspath('test.html')}") day = 15 # Original logic try: dp = page.locator(".datepicker-days") await dp.wait_for(state="visible", timeout=5000) cells = dp.locator("td.day:not(.old):not(.new)") count = await cells.count() print(f"Total cells found: {count}") for i in range(count): text = (await cells.nth(i).inner_text()).strip() if text == str(day): print(f"Trying to click cell {i} with text {text}") await cells.nth(i).click(timeout=1000) print(f"📅 Dia {day} selecionado.") return except Exception as e: print(f"ERROR: {type(e).__name__}: {str(e)}") await browser.close() if __name__ == "__main__": asyncio.run(test_date())