Rayrun
← Back to Discord Forum

Get locator to currently active/focused element?

I'm unsure how to accomplish this. I was hoping to do this using await page.evaluate(() => document.activeElement) but it gives an actual Element back and not a Locator.

This thread is trying to answer question "How can I get a locator to the currently active or focused element on a webpage?"

1 reply

I don't think you can do this. Locator, essentially, is just an instruction on how to locate element in page, it's not an element itself, so reverse thing (getting locator from document.activeElement which points to an element) doesn't really make sense.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].