Unable to check the checkboxlistitem

Ranorex Spy, Recorder, and Studio.
Priyanshu
Posts: 16
Joined: Wed May 22, 2019 5:48 am

Unable to check the checkboxlistitem

Post by Priyanshu » Fri May 24, 2019 11:38 am

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);
}
}
Attachments
CheckboxListItem.rxsnp
(369.09 KiB) Downloaded 10 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4967
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to check the checkboxlistitem

Post by odklizec » Fri May 24, 2019 11:57 am

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?
Last edited by odklizec on Mon May 27, 2019 11:09 am, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Priyanshu
Posts: 16
Joined: Wed May 22, 2019 5:48 am

Re: Unable to check the checkboxlistitem

Post by Priyanshu » Mon May 27, 2019 9:47 am

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?)

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4967
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to check the checkboxlistitem

Post by odklizec » Mon May 27, 2019 11:09 am

Hi,

Sorry, my mistake. Please try to change listItemsInfo.CreateAdapter to listItemsInfo.CreateAdapters.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Priyanshu
Posts: 16
Joined: Wed May 22, 2019 5:48 am

Re: Unable to check the checkboxlistitem

Post by Priyanshu » Mon May 27, 2019 1:06 pm

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.
Attachments
Capture.JPG
Capture.JPG (12.68 KiB) Viewed 62 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 4967
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Unable to check the checkboxlistitem

Post by odklizec » Mon May 27, 2019 1:24 pm

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Priyanshu
Posts: 16
Joined: Wed May 22, 2019 5:48 am

Re: Unable to check the checkboxlistitem

Post by Priyanshu » Tue May 28, 2019 6:44 am

Thanks ,

Spacebar solution worked!!