Select multiple checkboxes

Ranorex Spy, Recorder, and Studio.
Lyuba Boerma
Posts: 24
Joined: Mon Apr 01, 2019 12:12 pm

Select multiple checkboxes

Post by Lyuba Boerma » Mon Apr 01, 2019 1:38 pm

Hi.
I hope somebody will want to help me.
I saw similar topics , but they didn't help me..so i am a little bit confuse.
I need to select multiple checkboxes in a table, based on text value in a next column.
like on screenshot,..I need to select all checkboxes for elements with a name Seleniumsample.
For this checkbox i have a this location /dom[@domain='local.elabjournal.com']//table[#'table_sample']/tbody//span[@innertext=$varSampleName]/parent::td/preceding-sibling::td//input[@type='checkbox']

varSampleName - is my specific value on what I base my selection.
Ranorex can see it and in a spy he can count how many items exist now

So i need to write a code that will find all checkboxes that match to my selection .


Image
Image
Thanks!))
Attachments
Checkbox.rxsnp
(136.26 KiB) Downloaded 9 times

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

Re: Select multiple checkboxes

Post by odklizec » Mon Apr 01, 2019 2:25 pm

Hi,

The problem is, that the SELENIUMSAMPLE text in your table is stored with uppercase! So you must fill the variable with string using the same case! Or you must enclose the variable in case 'insensitive' regex, like this:
/dom[@domain='local.elabjournal.com']//table[#'table_sample']/tbody//span[@innertext~'^(?i:'+$varSampleName+')']/parent::td/preceding-sibling::td//input[@type='checkbox']
Then you can use code like this, to click each check box:
https://www.ranorex.com/help/latest/han ... oryelement

BTW, instead of referencing repo element directly in code, use method's parameter (RepoItemInfo) to pass the repo element to method.
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

Lyuba Boerma
Posts: 24
Joined: Mon Apr 01, 2019 12:12 pm

Re: Select multiple checkboxes

Post by Lyuba Boerma » Mon Apr 01, 2019 2:31 pm

No) the problem is that i don't know how to ask Ranorex to select more than 1 item based on my condition.
I can store my text in lower case..this is not my issue.

i need an example of code which will select all existing elements, which match my conditions.
Thanks

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

Re: Select multiple checkboxes

Post by odklizec » Mon Apr 01, 2019 2:49 pm

Hi,

What exactly do you mean by "code which will select all existing elements"?

The xpath I provided you, lists all checkboxes, which belongs to span with inner text containing 'SELENIUMSAMPLE'...
ListofCheckboxes.png
ListofCheckboxes.png (56.5 KiB) Viewed 200 times
If you now want to click (check) every single checkbox from the list of available checkboxes, you must use the sample code I directed you to. You just have to replace the repo element from the sample code, with repo element, using the above xpath. And then right after line...

Code: Select all

button.MoveTo();
you should add...

Code: Select all

button.Click(); 
method. You can, of course, replace 'button' and 'buttonList' with whatever you want. Hope this helps?
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

Lyuba Boerma
Posts: 24
Joined: Mon Apr 01, 2019 12:12 pm

Re: Select multiple checkboxes

Post by Lyuba Boerma » Tue Apr 02, 2019 9:13 am

Thanks for help!
It took me a lot of time and nervous but i made it work.

This my code using CreateAdapters method , for first create a list with items , which match my condition.
And then to set attribute value checked to True (instead of clicking) .

Code: Select all

  private void SelectMultipleCheckboxes()
		{
			
			// Create a list of adapters using the "Info" object
			IList<Ranorex.InputTag> inputList =
			repo.ELABJournal.Inventory_Screen.Sample_List_Screen.Checkbox_for__Created_ItemsInfo.CreateAdapters<Ranorex.InputTag>();
					
			System.Diagnostics.Debug.WriteLine(inputList.Count);
			foreach (Ranorex.InputTag input in inputList )
			{
			System.Diagnostics.Debug.WriteLine(input);	
			Report.Info("List: "+input);  	
			input.Checked="true";
			
			}
		

		}
Maybe it will also help somebody

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

Re: Select multiple checkboxes

Post by odklizec » Tue Apr 02, 2019 9:20 am

Hi,

Just one more thing. I would suggest to replace this part of code...

Code: Select all

private void SelectMultipleCheckboxes()
		{
			// Create a list of adapters using the "Info" object
			IList<Ranorex.InputTag> inputList = repo.ELABJournal.Inventory_Screen.Sample_List_Screen.Checkbox_for__Created_ItemsInfo.CreateAdapters<Ranorex.InputTag>();

with this...

Code: Select all

private void SelectMultipleCheckboxes(RepoItemInfo repoElement)
{
			// Create a list of adapters using the "Info" object
			IList<Ranorex.InputTag> inputList = repoElement.CreateAdapters<Ranorex.InputTag>();
Basically, you should avoid using repo items directly in code, like you did it, and rather reference them via method parameters. Then in recording, in which are you planning to use such method, link the repo element to given parameter. It's way better approach than hardcoding repo elements in code! ;)
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

Lyuba Boerma
Posts: 24
Joined: Mon Apr 01, 2019 12:12 pm

Re: Select multiple checkboxes

Post by Lyuba Boerma » Tue Apr 02, 2019 10:59 am

odklizec wrote:
Tue Apr 02, 2019 9:20 am
Hi,

Just one more thing. I would suggest to replace this part of code...
Okay.... i did it, it looks more nice..and works..But :D
Now for mu Count function he returns always a dubbel number.
if i have 7 elenemnts he will count 14
if only one - he will count 2

and i have no idea why :cry:
If i check via SPY he shows correct number of elements. Just put then in a list dubble....
What did i do wrong?))))
Thanks

Screen
https://monosnap.com/direct/sIboPhXx0HB ... J1nhf05Jlb

Code: Select all

public void SelectMultipleInput(RepoItemInfo repoElement)
        {
            
			//RepoItemInfo repoElement = repo.ELABJournal.Inventory_Screen.Sample_List_Screen.Checkbox_for__Created_ItemsInfo;
			
			// Create a list of adapters using the "Info" object
						
			IList<Ranorex.InputTag> inputList =
			repoElement.CreateAdapters<Ranorex.InputTag>();
			Report.Info("Qauntity of Samples: "+inputList.Count);	
			
			//System.Diagnostics.Debug.WriteLine(inputList.Count);
			foreach (Ranorex.InputTag input in inputList )
			{
			 	
			input.Checked="true";
			
			}
		
            		
        }

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

Re: Select multiple checkboxes

Post by odklizec » Tue Apr 02, 2019 11:06 am

Hi,
Lyuba Boerma wrote:
Tue Apr 02, 2019 10:59 am
Now for mu Count function he returns always a dubbel number.
if i have 7 elenemnts he will count 14
if only one - he will count 2
Unfortunately, this problem is caused by Ranorex 9.0 bug. But the good news is that Ranorex folks managed to find the root cause of the problem and it should be fixed in very soon to be released 9.0.1 ;)
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

Lyuba Boerma
Posts: 24
Joined: Mon Apr 01, 2019 12:12 pm

Re: Select multiple checkboxes

Post by Lyuba Boerma » Tue Apr 02, 2019 11:21 am

aaaahhhh)
okay, understood!
it is funny that when i was using first hardcode version - it was counting correct!)
but if i make it in a nice way - it created an issue ))


But , one more time, Thank you for help!