How to write xpath in groovy for table dom

105 Views Asked by At

HTML snippet

How to write XPath for above table 2nd row in Groovy (Geb and Spock framework)?

1

There are 1 best solutions below

0
kriegaex On

In Geb, usually we use CSS selectors rather than XPath in order to match DOM elements, even though, if you insist, a Selenium-like By.xpath is certainly possible.

How about one of these, depending on how specific you want to be?

$("tr", 1)                // 2nd row of any table on the page
$("table", 0).$("tr", 1)  // 2nd row of 1st table on the page

See e.g. "Book of Geb" chapters

Please do learn Spock and Geb basics. Stack Overflow is not a place for people who are too lazy to read manuals, only for developers who have done so, but still having concrete problems, presenting them in a reproducible way and clearly describing what they tried and how the actual result differs from the expectation. This was your free shot, because you are new here and we welcome newbies.