reading the CUITe_HtmlRadioButton values

Aug 26, 2013 at 6:37 AM
Edited Aug 26, 2013 at 6:38 AM
Hi Friends,

I am facing the problem while reading CUITe_HtmlRadioButton values.

Currently, in my application radio button shows. four option.
  1. None
  2. 1 ---> selected
  3. 2
  4. 3
I want to get value as "1" as per above selection.

I hv written code in CUITe_HtmlRadioButton.cs as below

public string SelectedValue{
        get
        {
            this._control.WaitForControlReady();             
           return this._control.Value;              

        }
    }
when I access the selectedValue method as below:

string strT24RegeralType = objFindAccount.radREFERALTYPE.SelectedValue;

its shows error saying that object reference null.

object :

public CUITe_HtmlRadioButton radREFERALTYPE = new CUITe_HtmlRadioButton("Name=radio:tab1:REFERAL.TYPE");


any idea what's wrong in the code

Observation :
I tried to select using select, select2 select3 and it will select as per value passed

when I highlight radiobutton control, it shows the highlight box on "None" option in radiobutton, means it is returning value is first option of the radiobutton but not selected one.

Please help me to get values which is selected
Aug 26, 2013 at 6:51 AM
Hi again,

Adding more information to above thread:

When I write this code:
string strT24RegeralType = objFindAccount.radREFERALTYPE.SelectedValue;

I will not get error but only Null values as it is selecting only "None" default first option.

if I write code like this.
string strT24RegeralType = objFindAccount.radREFERALTYPE.SelectedValue.toString();

in this case, I get error as below:
"Object reference not set to an instance of an object."
System.Exception {System.NullReferenceException}
Coordinator
Sep 9, 2013 at 7:51 AM
Hi neerajlad,

Here is a sample test that passes.
It determines if a radio button is selected\checked and also asserts on the selected radio button's value.
[TestMethod]
        public void GetSelectedValue_OfRadioButton_Succeeds()
        {
            // Arrange
            using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <input type=""radio"" name=""radio:tab1:gender.type.male"" value=""male"" checked=checked>Male</input><br/>
        <input type=""radio"" name=""radio:tab1:gender.type.female"" value=""female"">Female</input><br/>
        <input type=""radio"" name=""radio:tab1:gender.type.other"" value=""other"">Other</input><br/>
    </body>
</html>"))
            {
                CUITe_BrowserWindow.Launch(tempFile.FilePath);
                CUITe_BrowserWindow window = new CUITe_BrowserWindow("test");

                // Act
                CUITe_HtmlRadioButton genderTypeMale = window.Get<CUITe_HtmlRadioButton>("Name=radio:tab1:gender.type.male");

                // Assert
                Assert.IsTrue(genderTypeMale.IsSelected);
                Assert.AreEqual("male", genderTypeMale.ValueAttribute);

                window.Close();
            }
        }
Sep 24, 2013 at 9:00 AM
Edited Sep 24, 2013 at 9:02 AM
Hi Icnocop.

Thanks for your reply,

I could see you have stored value in object and the checking using ValueAttribute property, however when I use it It show me "null".

Error:
objORSDB.radRentalRestriction.ValueAttribute null string

However, Found workaround solution:


radRentalRestriction = objORSDB.radRentalRestriction.GetValueRadiobutton("Internal,Staff"); /// Internal and staff is value of Radio button

Function :
public string GetValueRadiobutton(string val)
    {
        string strResult = "";
        string[] words = val.Split(',');
        foreach (string word in words)
        {
            this.SetSearchProperty("Value", word);
            if (this._control.Selected)
            {
                strResult = this._control.Value;
            }
        }
        return strResult;
    }
Coordinator
Sep 24, 2013 at 11:00 PM
Hi neerajlad,

I can't really identify why this is working for me but not for you without looking at your html.

Can you provide the html you are using please?

It could be something like "checked=checked" is missing or different in your html than the sample code I provided and this is what's causing your issues.

If you actually run the test method on your machine, it should succeed without issue and so this indicates there is something wrong with the actual html being sent to the browser at the time the CUITe test is run for example.

Thank you.