andgursky andgursky - 4 months ago 33
Ruby Question

how to get data element by title index with capybara "find"?

I have html page:


I need to get data (td tag) by choosing title (th tag).
I'm trying:

page.find(:xpath, "//body/td[count(//body/th[contains(.,'a')]/preceding-sibling::th)-1]")

and I'm expecting to get "1" as returning value, but it returns "8".
It seems to me, that "count" doesn't work right. So, what am I doing wrong?


The logic should've counted preceding-sibling th plus 1, to find the correct position index of the th :


xpathtester demo

output :