Compare RadioBtn Checked State

Class library usage, coding and language questions.
regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Compare RadioBtn Checked State

Post by regex » Thu Sep 27, 2012 2:08 pm

I'm having a little frustration issue today. I want to compare Radio Button states from two different applications that represent the same workflow. I have a question if .GetAttributeValueText returns true if the button is checked. If that can be applied towards btnYes == True; or some other approach is needed. Just a little different angle on this issue might help.

I'm getting some Operator == cannot be applied to string and bool compile error with this:

Code: Select all

var isChecked = .Element.GetAttributeValueText("Checked");
            var faxNo = BtnNo.Element.GetAttributeValueText("Checked"); 
            var faxYes = BtnYes.Element.GetAttributeValueText("Checked"); 
        		
        		switch(isChecked, faxYes)
        		{
        			case 1:
        				isChecked && faxYes == "False";
        				Report.Info("No faxes were sent");
        				break;
        			case 2: 
        				isChecked && faxYes == "True"; 
        				Report.Info("Faxes were sent and match");
        				break;
        			case 3:
        				isChecked == False && faxTextField == True;
        				Report.Info("mismatch fail");
            			break;
        			case 4:
        				isChecked == True && faxTextField == False;
        				Report.Info("mismatch fail");
            			break; 
        		}
So I tried this instead:

Code: Select all

 if(faxYes && isChecked == true)
            {
            	Report.Info("both items match"); 
            }
            if(isChecked == faxYes)
            {
            	Report.Info("The checkbox is not returning a value for is checked.  The Item is matched");
            }
            if(isChecked == "True")
            {
            	Report.Info("The CheckBox is returning true"); 
            }

regex
Posts: 48
Joined: Tue Aug 14, 2012 5:47 pm

Re: Compare RadioBtn Checked State

Post by regex » Thu Sep 27, 2012 3:15 pm

I want to compare the two applications RadioButton Click State. I want to make sure if faxes were sent that a Checkbox within a console app is checked. Any ideas on how to compare the two states?

I refactored to this after not using Ternary operators.

Code: Select all

var isChecked = Element.GetAttributeValueText("CheckState"); 
        	var faxYes = Element.GetAttributeValueText("Checked");
        	
        	switch(isChecked)
        	{
        		case "True":
        			Validate.Attribute(faxYes, "Checked", isChecked);
        			break; 
        		case "False":
        			Validate.Attribute(faxYes, "Checked", isChecked);
        			break; 
        			
        	}

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Compare RadioBtn Checked State

Post by Support Team » Fri Sep 28, 2012 8:25 am

Hi,

You can for instance use this code in order to check if the two RadioButtons are checked:
bool rad1 = RadioButton1.Checked;
bool rad2 = RadioButton2.Checked;
        	
if(rad1 && rad2)
        Report.Info("True && True is True");
Regards,
Markus
Ranorex Support Team