ANSWER to Question 1 :
Use a loop to count the number of checkboxes and then to check the correct ones
ANSWER to Question 2:
Step 1. Record the step for selecting the radio buttons. (if 3 radio buttons record all 3)
Step 2. Select the 1st step and expand it. Make the 3 ID Methods are displayed. The 3 ID Methods have the following information for the 3 Radio Buttons.
Automatic:
* //input[@type=''radio'' and @value=''187309'']
* //input[@type=''radio'' and @value=''187317'']
* //input[@type=''radio'' and @value=''187325'']
X Path Values:
* //div[@id=''radioContentWrapper'']/input[1]
* //div[@id=''radioContentWrapper'']/input[2]
* //div[@id=''radioContentWrapper'']/input[3]
JavaScript:
* evalXPath(''//input[@type=''radio'' and @value=''187309'']'');
* evalXPath(''//input[@type=''radio'' and @value=''187317'']'');
* evalXPath(''//input[@type=''radio'' and @value=''187325'']'');
Steps 3:Consider the JavaScript method of 1st Radio Button. Paste the XPath value into the evalXPath step (within the quotes) so it now looks like this:
* evalXPath(''//div[@id=''radioContentWrapper'']/input[1]'');
Step 4: Escape the quotes ('') in the XPath expression by preceding them with a backslash () so this now looks like this:
* evalXPath(''//div[@id=''radioContentWrapper'']/input[1]'');
Step 5: To get all the radio buttons we remove the ordinal ([1]) so we now get:
* evalXPath(''//div[@id=''radioContentWrapper'']/input'');
Step 6: Assign this expression to a variable called options (any variable name can be used) that will become an array containing all the elements matching the XPath we defined:
* var options=evalXPath(''//div[@id=''radioContentWrapper'']/input'');
Step 7: To randomly select the radio buttons, add the below expression.
* random(options);
The final JavaScript should look like,
* var options=evalXPath(''//div[@id=''radioContentWrapper'']/input'');
* Random(options);
Step 8: Use 'Highlight' option to test whether the radio buttons are selected randomly. Results are shown after clicking on the 'Highlight' button.
Step 9: Run the script with commenting out the other 2 radio buttons and see the results.
Happy testing