Home > Enterprise >  How to work out if two different selectors point to the same element on a page?
How to work out if two different selectors point to the same element on a page?

Time:08-08

Given the following page

<div id="something">
    <div id="selected">
    </div>
</div>

In playwright I have two selectors like this..

selectorA = "#something >> div >> nth=1";
selectorB = "#selected";

These two selectors point to the same element on the page. How can I compare the two selectors / locators to figure out if they are pointing to the same element or not?

CodePudding user response:

You can retrieve both with document.querySelector and compare the two object, if it is the same element, they will reference the same one.

document.querySelector(selectorA) === document.querySelector(selectorB)

CodePudding user response:

You can use playwright inspector

https://playwright.dev/docs/debug#debugging-selectors

  • Related