Page 1 of 1

Check/Uncheck Checkbox based on Element Class

Posted: Wed Jul 29, 2015 8:00 pm
by keenon
Hello,

c# noobie here.

I have a checkbox that does not contain the checkbox attribute and it appears the only difference between checked and unchecked is the element's class.

Checked
<a title="Click to switch between your retirement and pre-retirement views" class="RetirementToggleButton RetirementToggleButtonSprite RetirementSwitch_On" id="RetirementToggleSwitch" href="/lbs/Clix/Clix/UpdateRetirementToggleSwitch"></a>

Unchecked
<a title="Click to switch between your retirement and pre-retirement views" class="RetirementToggleButton RetirementToggleButtonSprite RetirementSwitch_Off" id="RetirementToggleSwitch" href="/lbs/Clix/Clix/UpdateRetirementToggleSwitch"></a>

I would like to get the value of the class and then take action based upon what class is passed through. I am sure I would have to write and IF statement, but I have been struggling to nail it down. I'm thinking this is much easier that I am making it seem to be. Any Suggestions?

Thanks

Re: Check/Uncheck Checkbox based on Element Class

Posted: Wed Jul 29, 2015 8:23 pm
by krstcs
Your path, assuming the id is unique on the page, could be this (not sure if you were having issues with the XPath, but here it is anyway):

Code: Select all

//a[#'RetirementToggleSwitch']
Then, in code, to get the value of the class, do this:

Code: Select all

string retirementClass = repo.RetirementToggleSwitch.Element.GetAttributeValueText("class");
To get whether the class contains the on/off you can do this:

Code: Select all

bool isOn = repo.RetirementToggleSwitch.Element.GetAttributeValueText("class").Contains("RetirementSwitch_On");
Change "repo.RetirementToggleSwitch" to whatever your actual repo item's folder structure and names are. You can also check for off specifically by changing "RetirementSwitch_On" to "RetirementSwitch_Off" (make sure to change the variable name to fit...).


The Ranorex API is located here: http://www.ranorex.com/Documentation/Ranorex/

Hope this helps!

Re: Check/Uncheck Checkbox based on Element Class

Posted: Wed Jul 29, 2015 9:10 pm
by keenon
You my friend are a life saver! I got it working exactly how I want it with your help. I appreciate all of your help!

Re: Check/Uncheck Checkbox based on Element Class

Posted: Thu Jul 30, 2015 2:46 pm
by krstcs
You're welcome!