With Playwright it is possible to take over an existing browser session and this could be integrated with an AI agent to perform actions as needed. My preferred solution as I don’t always know exactly in advance how a webpage will behave.
Not sure about Selenium though. I’d expect one writes the scripts as needed and spins up the browser instance.