0

I tried to find all the elements that has the text "Operation" inside them. I only see one such element visible, but Playwright is giving me 19:

 self.page.locator('*', has_text='Operation').click()

When I run this selector in the developer tools:

$x('//*[contains( text(),"Operation" )]')

I see only a single element.

What am I doing wrong here?

Tal Angel
  • 1,301
  • 3
  • 29
  • 63
  • maybe looking inside a specific div or container will be more robust. looking inside the whole page can show such inconsistencies imho. – Kiran Parajuli Aug 02 '22 at 08:44

1 Answers1

1

You can use the text locator and also add more Texts along with Operation to pinpoint your element more accurately.

page.locator("text=Operation").click()
page.locator("text=Some more words Operation").click()

Or, you can also use the Nth element selector if you know the position of the text occurrence. Starts from 0

page.locator("text=Operation >> nth=0").click()
Alapan Das
  • 17,144
  • 3
  • 29
  • 52