Page 1 of 1

Uncheck multiple CB

Posted: Tue Oct 05, 2021 8:44 am
by yaro2o
Hello I have a question. I have a list of 16 checkboxes and I need only 1 of them selected and the rest unchecked, ranorex must check that the selected cb is checked and that the rest is unchecked and if one of them is also checked then uncheck it

Re: Uncheck multiple CB

Posted: Tue Oct 05, 2021 8:56 am
by odklizec
Hi,

Please upload a Ranorex snapshot (NOT screenshot) of the UI in question (with all checkboxes). Without, at very least, snapshot it's hard to suggest something reliable.

Generally speaking, you must create a repo item with xpath, which returns all checboexs. Then you need to create a list of items, using code as described here:
https://www.ranorex.com/help/latest/han ... oryelement
Using the above code (of course modified), you can get the state of each checkbox and eventually uncheck it if checked.

Re: Uncheck multiple CB

Posted: Tue Oct 05, 2021 9:27 am
by yaro2o
Attached I am sending a snap

Re: Uncheck multiple CB

Posted: Tue Oct 05, 2021 9:29 am
by yaro2o
I need to Check or uncheck only first CB column

Re: Uncheck multiple CB

Posted: Tue Oct 05, 2021 10:38 am
by odklizec
Hi,

Thanks for the snapshot. So, basically, you need to create a repo element with xpath like this:

Code: Select all

/form[@name='PraDialog']//checkbox[@instance='0']
This will return all checkboxes from left column.
Now you need to pass the repo element to UserCode like this:

Code: Select all

private void UncheckAllChecked(RepoItemInfo repoElement) 
{
    IList<Ranorex.CheckBox> checkBoxList= listItemsInfo.CreateAdapters<Ranorex.CheckBox>();
    foreach (Ranorex.CheckBox chekBoxItem in checkBoxList)
    {
        if (chekBoxItem.Element.GetAttributeValue<bool>("Checked"))
      	{
      	    Report.Info("CheckBox Item: " + chekBoxItem.Find<Ranorex.Text>("./preceding-sibling::text").Element.GetAttributeValueText("Text").ToString()); //this should return name of check box
            chekBoxItem.Click(); 
      	}
    }
}
I've not tested the code, so it may need some refinements? But generally, it should give you an idea what to do ;)

Re: Uncheck multiple CB

Posted: Tue Oct 05, 2021 11:41 am
by yaro2o
I write something like this
IList<Ranorex.CheckBox> TCheckBoxList = 
 			repo.PraDialog.TCheckBoxInfo.CreateAdapters<Ranorex.CheckBox>(); 
 

			foreach (Ranorex.CheckBox TCheckBox in TCheckBoxList) 
				{ 
				if(TCheckBox.Checked)
				{
					TCheckBox.Click();
				}
				}
this code uncheck all CB and then I have a recording where I click on the nr of CB from variable
I had no idea or knowledge of how to do it with code
generally works :D