cancel
Showing results for 
Search instead for 
Did you mean: 

Xpath Get last matching result

SOLVED
Highlighted
Occasional 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 ?

 

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Xpath Get last matching result

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

View solution in original post

1 REPLY 1
Highlighted
Community Leader

Re: Xpath Get last matching result

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

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors