java - last() is not applied -
i using selenium , java write test, below dom:
<body> <div class='t'><span>1</span></div> <div class='t'></div> <div class='t'><span>2</span></div> <div class='t'><span>3</span></div> <div class='t'><span>4</span></div> <div class='t'><span>5</span></div> <div class='t'><span>6</span></div> <div class='t'><span>7</span></div> <div class='tt'></div> </body>
when use: //div[@class='t'][last()]
get:
<div class="t"><span>7</span></div>
but when use: //div[@class='t' , last()]
get:
<div class="t"><span>1</span></div> <div class="t"/> <div class="t"><span>2</span></div> <div class="t"><span>3</span></div> <div class="t"><span>4</span></div> <div class="t"><span>5</span></div> <div class="t"><span>6</span></div> <div class="t"><span>7</span></div>
it's last()
not applied second xpath, why?
//div[@class='t'][last()]
... means pick element list of matches (where @class='t'
) index last, want.
with //div[@class='t' , last()]
, already-calculated value of last()
applied each match in list purely on basis of being != 0, , cause div
matcher return false if last()
zero. in other words, last()
not used select single node list. that's not want.
for example: if last()
evaluates 5, //div[@class='t' , 5]
return every matching element in list because 5 != 0.
the net result if any nodes matched (last()
> 0), all of them returned.
see also: xslt getting last element
Comments
Post a Comment