0

I'm trying to find an element with a specific nth index as a CSS expression.

How can I fix my code without changing the CSS expression?

try:
    expect(self.page.locator('div[class="some-class"]:nth(3)')).\
                   to_be_visible(timeout=20000)
    return True
except AssertionError:
    return False

The error I get is:

{Error}DOMException: Failed to execute 'querySelectorAll' on 'Document': 'div[class="some-class"]:nth(3)' is not a valid selector.

Tal Angel
  • 1,301
  • 3
  • 29
  • 63

2 Answers2

1

Your locator should look like this. Replace ":" with ">>"

div[class="some-class"]>>nth=3
itronic1990
  • 1,231
  • 2
  • 4
  • 18
1

You can also do something like this:

self.page.locator('div.some-class').nth(3)
//or
self.page.locator('div.some-class').nth(4)
Alapan Das
  • 17,144
  • 3
  • 29
  • 52