How can I find an element using Playwright using a single locator phrase?
My element is:
<div class="DClass">Hello</div>
I wish to find the element by its class and text:
myElement = self.page.locator('text="Hello",[class="DClass"]')
Why it does not work?
If you separate the selectors with a ,
that's an or
. You can chain selectors using >>
.
myElement = self.page.locator('text="Hello" >> [class="DClass"]')