I'm using a CSS selector, but still getting locator objects.
Specifically, I want to walk through a list of checkboxes and verify whether each one is checked or not, as expected.
Then one of the elements has a following sibling ... just a
div, and I'd like to verify whether it's present or not.
I know that locators have a builtin await-er, but that's not an issue in this case, as far as I can tell.
This thread is trying to answer question "How do I get the underlying DOM object from a locator?"
Related Ask AI answer for "What is the method to retrieve the DOM element from a locator in Playwright?".
In Playwright, you can use the
Here's how you can do it:
const locator = page.locator('your-locator');
const handle = await locator.evaluateHandle((element) => element);
your-locator with your actual locator expression. The
Once you have the handle, you can perform various operations on it using Playwright's API. For example, you can interact with its properties or call methods on it.
Remember, when using
evaluateHandle, Playwright automatically serializes and deserializes complex objects between Node.js and browser contexts. This means that even if your locator matches multiple elements, only their handles will be returned rather than their full representations.
So, with Playwright's
evaluateHandle method and a locator expression, you can easily get handles to underlying DOM objects and perform further actions on them in your automation scripts.
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@example.com.