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
Check/Uncheck Checkbox based on Element Class
Re: Check/Uncheck Checkbox based on Element Class
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):
Then, in code, to get the value of the class, do this:
To get whether the class contains the on/off you can do this:
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!
Code: Select all
//a[#'RetirementToggleSwitch']
Code: Select all
string retirementClass = repo.RetirementToggleSwitch.Element.GetAttributeValueText("class");
Code: Select all
bool isOn = repo.RetirementToggleSwitch.Element.GetAttributeValueText("class").Contains("RetirementSwitch_On");
The Ranorex API is located here: http://www.ranorex.com/Documentation/Ranorex/
Hope this helps!
Shortcuts usually aren't...
Re: Check/Uncheck Checkbox based on Element Class
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!