LR12.53 TruClient FireFox. How to enumerate objects on a page fast?

I need to know how many links or buttons with particular properties page displays. I do not need a unique object to performa an action on. I just need a number, preferably fast. If I use following JavaScript as ID Method: 

evalXPath("//ul[@class=\"some-list\"]/li[@some-status='THE STATUS I AM LOOKING FOR']");

then "Evaluate Java Script Code" Fails immediately with ** 7: Evaluate JavaScript code var SuitableLinks = ev... FOR']"); ** failed - exception occurred: ReferenceError: evalXPath is not defined

"Evaluate JS on Object" Spends time "Waiting For Object" then returns:
** 7: Evaluate JavaScript [Code] on SuitableLinks link ** failed - target object was not found.

I can force "Evaluate JS on Object" to give me what I want by  changing JavaScript to:

var SuitableLinks = evalXPath("//ul[@class=\"some-list\"]/li[@some-status='THE STATUS I AM LOOKING FOR']");
ArgsContext.item = SuitableLinks.length;

but it still wastes time "Waiting For Object", and it still fails, so I have to use "Catch Any error" and then use Log option "Do not report errors caught by 'Catch Errors' step". I want a better solution.

Is there really no way to count objects?

Do I need to write my own JavaScript function for this?

 

 

  • Hi,

    You need to write JavaScript code for that. You can run it in a regular Evaluate JavaScript step outside the context of Generic Object step or Evaluate JS on object.

    You can use the same code you shared or use document.getElementsByTagName.

    BTW: ArgsContext is not needed in this statement. You can save the length to item variable. TruClient automatically saves it in the ArgsContext object.

    ArgsContext.item = SuitableLinks.length;

    Regards,

    Shlomi