Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..
225 views

TruClient: unable to select random picklist with skipping first item (JS Math functions left out?)

With TruClient it used to be possible to select a random picklist with skipping first item (ordinal) with the following JS code (see http://www.sqaforums.com/attachments/719896-TruClientRandomListbox.pdf).

In the Arguments -> Ordinal box:

var optionindex = Math.floor((object.length – 1) * Math.random()) + 2;
optionindex;

 

When running this results in an "illegal character" error.

When leaving out the Math functions it works out fine. Could it be that the JavaScipt Math library is not supported anymore?

Appreciate your help.

Kind regards.,
Okke 

0 Likes
2 Replies
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Re: TruClient: unable to select random picklist with skipping first item (JS Math functions left out

A simple JS evaluate at the beginning of the script 

window.alert(Math.floor(Math.random(2)));

renders ok, so Math methods are working properly.

What else could be wrong?

 

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: TruClient: unable to select random picklist with skipping first item (JS Math functions left out

Hello Okke,

In order to try to skip the first element of the list in a random function, please try with the following:

var array = evalXPath("//form[@id=\"SelectSiteForm\"]/table/tbody/tr");

var len = array.length;

var ran = Math.floor((Math.random() * (len-1)) + 2);

evalXPath("//form[@id="SelectSiteForm"]/table/tbody/tr[“+ ran +“]/td[1]");

 

Regards,

Joel Aguilar Cerna
SW Support Technical Consultant
San Jose, Costa Rica
microfocus.com
Micro Focus

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the STAR at the bottom left of the post and show your appreciation.
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.