Page 1 of 1

Unable to check the checkboxlistitem

Posted: Fri May 24, 2019 11:38 am
by Priyanshu
Hi Team,

I am working on windows based application where I want to click on checkboxlistitem, I am able to click on listitem as attached in snpashot.

I am trying with below code.

Ranorex.List casList= labWinRepo.EfterbestaellningAnalyser.EditPnl.CLBlocknr;IList<ListItem> listOfChkBox=casList.FindChildren<ListItem>();
int cnt = listOfChkBox.Count;
foreach(Ranorex.ListItem chkBox in listOfChkBox)
{
chkBox.Focus();
Mouse.Click(chkBox);
}
}

Re: Unable to check the checkboxlistitem

Posted: Fri May 24, 2019 11:57 am
by odklizec
Hi,

You don't have to use FindChildren at all and I would personally avoid hardcoding repo item in code. I would suggest to create a method, with RepoItemInfo parameter, pointing to repo element returning list of all ListItems, with xpath like this:

Code: Select all

/form[@name='SyLaEfterbestFrm']/container[@name='editPnl']//list[@name='CLBlocknr']/listitem
Then use this code, which should create a list of all list items and click them:

Code: Select all

public void ClickListItems(RepoItemInfo listItemsInfo)  // where listItemsInfo points to the repo element, with xpath returning list of all listitems
    {
        IList <Ranorex.ListItem> listItemsList = listItemsInfo.CreateAdapters<Ranorex.ListItem>(false);
        foreach (Ranorex.ListItem listItemSingle in listItemsList )
        {
            listItemSingle.Click();
        }
    }
Hope this helps?

Re: Unable to check the checkboxlistitem

Posted: Mon May 27, 2019 9:47 am
by Priyanshu
Hi ,
I tried with below code but getting error.
Cannot implicitly convert type 'Ranorex.ListItem' to 'System.Collections.Generic.IList<Ranorex.ListItem>'. An explicit conversion exists (are you missing a cast?)

Re: Unable to check the checkboxlistitem

Posted: Mon May 27, 2019 11:09 am
by odklizec
Hi,

Sorry, my mistake. Please try to change listItemsInfo.CreateAdapter to listItemsInfo.CreateAdapters.

Re: Unable to check the checkboxlistitem

Posted: Mon May 27, 2019 1:06 pm
by Priyanshu
Hi ,

As attached in snapshot, In this List 'CLBlocknr' hierarchy I am trying to click on /listitem[@name='/A/1 - abc'] but if you see the advance settings Under Dynamic Checked is false , but when I manually change it to true .. listitem[@name='/A/1 - abc' is checked .. but with the below code I am not able to click on checkbox but able to click on string of listItem. Please suggest.

Re: Unable to check the checkboxlistitem

Posted: Mon May 27, 2019 1:24 pm
by odklizec
Hi,

Well, the snapshot does not differ between the checkbox square and its description. Which means, there is no way to track and click just the checkbox element. I guess that if you manually click (simple left click) the checkbox name, it will not check the checkbox square as well? In this case, try double click action. Depending of the checkbox implementation, double click could help.

Another way could be to click on string, just to select the item you want to check, and then send 'Space' shortcut, which should check the checkbox. And yet another solution could be using SetValue (Checked) or InvokeAction (Check/Uncheck or DoDefaultAction) actions.

Re: Unable to check the checkboxlistitem

Posted: Tue May 28, 2019 6:44 am
by Priyanshu
Thanks ,

Spacebar solution worked!!