pythonplaywrightplaywright-python

Playwright - Checking Class Name of an Element


I'm testing a site which has a list that needs to be opened or is open already. The class of the element changes according to the state it is currently in.

So the element is either

div class="list-open"

or

div class="list-closed"

My script has to check this to make sure to open the list if it is closed to continue the algorithm. How can I check the class name with Playwright for this?


Solution

  • You can ask for the class name of the element.

    page.locator("div").evaluate("node => node.className")