Search code examples
pythonbrowsertabsplaywrightplaywright-python

Close or Switch Tabs in Playwright/Python


I'm doing an automation, at the time of download it opens a tab, sometimes it doesn't close automatically, so how can I close a tab in playwright using python?


Solution

  • I managed to make a code that closes only a specific tab!

    all_pages = page.context.pages
    await all_pages[1].close()