1

I have 4 tables on my web page, and I need to identify the header for all tables. Now issue is they all have same DOM structure so for identifying them I need to use indexing with xpath like:

(//span[@data-testid='headcol-0']/div/div[1])[2] here last [2] is index for second table identification. So when I have used this xpath it is failing and not identifying the locator correctly. Do we have any other syntax for indexing here in @karate

Saurabh Garg
  • 135
  • 6

1 Answers1

0

Try using a locateAll() and then an index. Note that this may not work in 0.9.5, please try 0.9.6.RC4

* def temp = locateAll("//span[@data-testid='headcol-0']/div/div[1]")[1]

Also prefer CSS locators like this:

* locate('table:nth-child(3)').highlight()

Also new in 0.9.6.RC4 - if you can easily find a child in that table, you can use element.parent to navigate "upwards":

* def temp = locate('.my-class').parent.parent
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248