Highlighted
Contributor.
Contributor.
520 views

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?

 

 

Tags (3)
0 Likes
1 Reply
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

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

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 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.