xPath question

6 views
Skip to first unread message

lemmerich

unread,
Jun 29, 2009, 12:55:59 PM6/29/09
to Java_Official
Hey Guys,

How do i select the first span that has the class "foo" in the code
below?

<html>

<body>
<div>
<span class="foo">Something 1</span>
</div><div>
<span class="foo">Something 2</span>
</div><div>
<span class="foo">Something 3</span>
</div><div>
<span class="foo">Something 4</span>
</div><div>
<span class="foo">Something 5</span>
</div>
<body>


</html>


I have tried these:
//descendant::span[@class='foo'][index]
-> works great to identify all but the first one (when i try the index
= 1 it returns all the spans)

//span[@class='foo'][index]
-> only works for index = 1 and brings all spans instead of the first
one

i wanted something like that instead of the full path (like //html/
body/div[1]/span )

Am i missing something on those two attempts?

Thanks in advance
Reply all
Reply to author
Forward
0 new messages