0

I have a div with text, for example 'abc'.

I wish to find the first div above that element that has a class called 'myClass'. How to do it? My code doesn't work:

self.page.locator(f'[class="myClass"] >> nth=0:'                                        
f'above(:text("abc"))').count()

Image example

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

1 Answers1

0

You can do something like this:

self.page.locator(f'div:above(:text("Security Notifications"))').count()
//or
self.page.locator(f'div:left-of(:text("Security Notifications"))').count()
//or
self.page.locator(f'div:near(:text("Security Notifications"))').count()
Alapan Das
  • 17,144
  • 3
  • 29
  • 52