If Statements

Best practices, code snippets for common functionality, examples, and guidelines.
Hammad.Malik
Posts: 1
Joined: Tue Oct 06, 2015 11:54 am

If Statements

Post by Hammad.Malik » Tue Oct 06, 2015 11:59 am

Hello Team

I am new to Ranorex and need some help with If statements during recording session.

I land on a page, If the Checkbox is unchecked, I would like Ranorex to check it and move onto the next one

likewise if we arrive on the page and the Checkbox is already checked, I would like it to ignore and move onto the next checkbox and likewise continue.

Any help will be apprecaited.

Hammad

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

Re: If Statements

Post by odklizec » Tue Oct 06, 2015 12:26 pm

Hi Hammad and welcome here,

There is currently no way to perform conditional statements within Recorded steps. The only way to achieve what you want is to use User Action or Code Module.

What you can do is to convert the recorded "check" step to user code, then add "If" statement (evaluating the actual state of checkbox) and do whatever you want with it based of its state.

There are many posts discussing evaluation of checkboxs via code. Try for example these...
http://www.ranorex.com/forum/how-to-che ... t6087.html
http://www.ranorex.com/forum/validate-s ... t7256.html
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

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

Re: If Statements

Post by CookieMonster » Tue Oct 06, 2015 1:51 pm

Hi Hammad,

we are handling Radiobutton, Checkboxes with the following approach.
We pass a boolean, if the checkbox has to be selected or not. That means if you want that checkbox is selected you pass true. So if your checkbox is already set, then noting happens otherwise the checkbox will be selected.

We have implemented method like this (simplified):
private void ClickToggleWebElement(RepoItemInfo repoInfo, bool selected)
{
        Unknown unknown = base.CreateUnknown(repoInfo);
        InputTag inputTag = unknown.Element;
	if (!selected && bool.Parse(inputTag.Checked))
	{
		inputTag.Checked = "false";				
	}
 // add your own code
}
I hope this helps.
Regards
Dan