0

so will something like this work using Hpple Xpath

//a[4]

The fourth tag in a html tree? Or do i need to do it programmatically by counting in a for() loop?

JLRishe
  • 99,490
  • 19
  • 131
  • 169
Nxtmind
  • 57
  • 8

1 Answers1

1

The XPath for the fourth <a> in an HTML document is:

(//a)[4]

Your example //a[4] will produce a set of all <a>s that are the fourth <a> in their respective parent, and that is not what you want here.

See also: https://stackoverflow.com/a/14209492/1945651

Community
  • 1
  • 1
JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • wait so will this work //table[@class='grid']/tbody/(tr)[4]/(td)[16] – Nxtmind Mar 27 '13 at 21:05
  • That's not valid XPath, but what are you trying to accomplish with it? It would be valid without the parentheses, but is there only one `grid` table on the page or several? If there are several, do you want to access all of them, or just one? – JLRishe Mar 28 '13 at 02:50
  • //table[@class='grid']/tbody/tr[4]/td[16] So would this work to access only that specific box on the table. – Nxtmind Mar 28 '13 at 15:48
  • Yes, assuming there is only one table with a `class` attribute value of "grid". – JLRishe Mar 29 '13 at 04:11