I have the following HTML:
<div>
<p>foo</p>
<p class='foo'>foo</p>
<p class='foo'>foo</p>
<p>bar</p>
</div>
How can i select second P tag with class ‘foo’ by XPath?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following expression should do it:
Edit: The use of
[2]here selects elements according to their position among their siblings, rather than from among the matched nodes. Since both your tables are the first children of their parent elements,[1]will match both of them, while[2]will match neither. If you want the second such element in the entire document, you need to put the expression in brackets so that[2]applies to the nodeset: