ARD
ARD

Reputation: 49

Xpath for Multiple table td element

There is a webtable in which I need to select from 1st row only 2nd 3rd and 4th column. I have tried using AND operator to select multiple td but that xpath is not working.

Xpath for 1st row which works good

((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]

Xpath to select td 2nd works good

((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]//td[position()=2]

Xpath to select td 2nd 3rd and 4th column. NEED HELP not working

 ((//div[contains(@id,'ReportGridStyle_forRW')])[2]//tbody/tr)[2]//td[position()=2 and position()=3 and position()=4]

Upvotes: 1

Views: 2492

Answers (1)

Dmitri T
Dmitri T

Reputation: 168082

If you really want to use XPath go for the following:

  • descendant axe for traversing the table tag to locate the first tr element
  • position() function to limit the rows to "interesting" only:

    //table/descendant::tr[1]/td[position() >= 2 and position() <= 4]
    

References:

Also be aware that you can use Table class from the Html Elements framework - it provide you a clear API for working with Tables.

Upvotes: 1

Related Questions