Forum Discussion

longchasen's avatar
longchasen
Contributor
5 years ago

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()='Tota...
  • BenoitB's avatar
    5 years ago

    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;