Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find first element above other element using Playwright

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading