Forum Discussion
In my case I have tried to implement generic function to determine which radio button need to be clicked but it is not working . Besides I don't see any testcomplete methods for radio buttons just like we have for drop down values . We want to select the radio button based on the R# value.
Please advise
Thanks
Nishchal
Couple of things:
1) Can you post the code that you are using for your radio button generic?
2) Can you post screenshots from your object browser showing
a) The parent object containing the radio buttons and its properties
b) At least one radio button object and its properties.
This will help us help you in correcting your generic.
- nisgupta7 years agoValued Contributor
here is the below code.
function SelectRadioButton(RadioButtonObj,RadioButtonValue){
var selectRadioButtonValueSuccess = false;
if(RadioButtonObj.WaitForProperty("Enabled", true,3000))
{
var radiobuttons = RadioButtonObj.wItemCount;
for(i=0; i<radiobuttons; i++){
if(radiobuttons.wItem(i) == RadioButonValue)
{
RadioButtonObj.Click();
selectRadioButtonValueSuccess = true;
break;
}
}
if(selectRadioButtonValueSuccess == false)
{
Log.Error("No Radio Button Values are found");
}
}
}- nisgupta7 years agoValued Contributor
Attached are the 2 folders
radiobutton_parent.zip
radiobuttonObjects.zip
Let me know if you need more details
Thanks
NG
- tristaanogre7 years agoEsteemed Contributor
Actually, this appears to be a bit of a different situation than just selecting a radio button from within a group. For example, we have in our test application something that looks like this:
This first shows the different radio buttons presented on the web page in individual groupings.
This is what one of those groupings looks like in the object browser
And this is what I have them mapped as. These are static controls on a particular page that are always in the same place, organized in the same way. So, I can statically map them because I can depend upon them always looking the same way.
So, the way I'd make this a generic function would be something like (JavaScript)
function clickRadioButton(parentGroup, buttonName) { var buttonObject; buttonObject = parentGroup.WaitAliasChild(buttonName, -1); if (buttonObject.Exists) { buttonObject.Click(); } } function test() { clickRadioButton(Aliases.myPage.radiogroupA, 'radiobuttonNA'); }
However, what you have is not quite the same thing. What it appears to be to me is that you have a dynamic table of employees, each row has a radio button that you want to click on. So, you're task is actually two-fold:
1) Find the particular row that corresponds to the employee you wish to select2) Click the radio button on that row.
So, first, I'd have a piece of code specifically to find the row in the table of choice. We already utilize a piece of code for that
function findRow(tableObject, stringSearch, searchColumn, maxRows = 0) { var cellFound = Utils.CreateStubObject(); var upperLimit; if (maxRows == 0) { upperLimit = tableObject.RowCount; } else { upperLimit = maxRows; } if ((searchColumn == 999) || (searchColumn == undefined)) { cellFound = tableObject.FindChild('innerText', aqConvert.VarToStr(stringSearch) + '*', 0, true); } else { for (var i = 1; i < upperLimit; i ++) { if (aqString.Trim(tableObject.Cell(i, searchColumn).innerText) == aqString.Trim(aqConvert.VarToStr(stringSearch)) ) { cellFound = tableObject.Cell(i, searchColumn); break; } } } if (cellFound.Exists) { return cellFound.RowIndex; } else { return -1; } }
So, you'd utilize this code in another method that would specifically search for the employee you want and then click on the appropriate radiobutton in that row. Something like:
function clickRadioButtonInRow(tableObject, searchText, searchColumn, radiobuttonColumn = 0) { var rowNumber; rowNumber = findRow(tableObject, searchText, searchColumn); if (rowNumber == -1) { throw Error('Could not find the search text: ' + searchText); } tableObject.Cell(rowNumber, radiobuttonColumn).RadioButton('*').Click(); }
This should be generalized enough that, given any table that has a radio button that you wish to click on, will search that table for the button based upon the search text and then click on it. This is pretty close to what we're doing in a similar section of our own application.
Related Content
- 11 years agojose_pita
- 4 years agoAutomation1id