Ask a Question

Xpath Get last matching result

SOLVED
longchasen
Contributor

Xpath Get last matching result

I have an xpath expression like this: 

 

//td[@div='id']/nobr[text()='Total AR:']

 

Upon checking on the inspector element there are multiple matches, both on /td[@div='id'] and nobr[text()='Total AR:']. I only need to get the last result as im sure thats what i need. Basically im trying to do something like this:

 

//td[@div='id'][last()]/nobr[text()='Total AR:']

 

how can i get the last result ?

 

1 REPLY 1
BenoitB
Community Hero

Perhaps use the array return of xpath query.

And take the last one.

 

objectfind = MyPage.contentDocument == null ? null : MyPage.FindChildByXPath(toFind);
if ((typeof objectfind != 'undefined') && (objectfind != null)) {
  objectfind = (new VBArray(objectfind)).toArray();
  return (objectfind[objectfind.length-1]);
}
else
  return null;

Un sourire et ça repart

cancel
Showing results for 
Search instead for 
Did you mean: