Highlighted
Absent Member.
Absent Member.
1715 views

how can i select the radio button randomly in truclient?

Hi

i want to select the radio button randomly below are the xpath and javascript values

Id Method: XPath

Xpath:   //input[@type="radio" and @name="seatPref" and @value="Window"]

and

/html/body/blockquote/form/table/tbody/tr[5]/td[1]/label[2]/input

Id Method: JavaScript

JavaScript: evalXPath("//div[@id=\"radioContentWrapper\" and @name=\"seatPref\" and @value=\"Window"]");

 

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: how can i select the radio button randomly in truclient?

Hi Somu210, 

Please find  step by step instructions in the following knowledge document which explains how to select a random checkbox value. 

https://softwaresupport.hp.com/group/softwaresupport/search-result/-/facetsearch/document/KM01788615

The idea is that you need to:

1. Record a few steps clicking on different elements from the group.
2. Open the steps and change the ID Method to JavaScript in the step object section.3. Find the difference in the the evalXPath

for example 

/html/body/blockquote/form/table/tbody/tr[5]/td[1]/label[2]/input

/html/body/blockquote/form/table/tbody/tr[4]/td[1]/label[2]/input

4. Substitute the difference with a parameter for example idr which contains a random value, calculated with formula for calculating a random value in not exceeding the number of the available radion buttons.

Please check the sample code in the snapshot below: 

 Kind regards, 

Vesela 

 

HPE Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
Highlighted
Absent Member.
Absent Member.

Re: how can i select the radio button randomly in truclient?

Hi vmanolova

Thank you for giving reply

i used your code but the problem is by default it is selecting the first value and it is not chaqnging randomly 

please help me

Thanks in Advance

 

 

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: how can i select the radio button randomly in truclient?

Hi,

 

Please look in the code in the snapshot in the JavaScript editor.

There is as sample how to:

  1. select all radio buttons
  2. check the number of the radio buttons
  3. use this number in the formula for calculating a random value idr.
  4. Then you need to substitute the changing number in the xpath with the idr.

You should follow the sample and adjust it to the specific xpath for your radio buttons. 

Kind regards,

Vesela

HPE Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: how can i select the radio button randomly in truclient?

Hi Vesela

This is my complete code

var radioArray = document.querySelectorAll('input[type="radio"]').length;
//var max = radioArray.length;
var randomID = Math.floor(Math.random() * ((radioArray+1)-1))+1;

by default it is selecting first value suppose if i place 2 in 1 at that time it is selecting secondn value i am unable to generate random value.

how can i select the generate the random value
//var xpath = "/html/body/blockquote/form/table/tbody/tr[5]/td[1]/label["+randomID+"]/input";
//evalXPath(xpath);

//evalXPath("//div[@id=\"radioContentWrapper\" and @name=\"seatPref\" and @value=\"Window\"]");
var xpath ="(//input[@type=\"radio\" and @name=\"seatPref\"])["+randomID+"]";
evalXPath(xpath);

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: how can i select the radio button randomly in truclient?

Hi Somu210,

The formula for geting the random number in an intervals that do not start with 1 is: 
Math.floor(Math.random() * (max - min)) + min;
It returns a random integer between min (included) and max (excluded)

You should modify it according to your needs. 

The script in the snapshot selects a a random checkbox on each reply in my lab. 

Kind regards, 

Vesela

HPE Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Re: how can i select the radio button randomly in truclient?

Thanks for this useful information,i was looking for the same, from where we can get that formula to calculate the parameter we want to substitie,is it somthing  from java  IDE or in vugen tools itself.

Regards,
hp4u
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: how can i select the radio button randomly in truclient?

Hi, 

It is JavaScipt. For more details about Math.random() function and haw it can be used, please check:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

Kind regards, 
Vesela 

HPE Support
If you haven’t tried it yet, come and join us in our entitled forums at Support Customer Forums

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution and give Kudos to the author for their assistance.
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.