I'm trying to select a radio button in coded UI which is hidden. I'm doing hand coding and using Visual Studio Professional 2015.
Here is my Radio button property:
<span id="AddExtraDataWidget_un10_NoorgSportInd_WRAPPER">
<input id="AddExtraDataWidget_un10_No_GROUP" class="Radio" type="radio" value="AddExtraDataWidget_un10_No" onfocus="null" onblur="null" onclick="null;showHideCntrldByCaption(this.checked,'','No','false')" name="AddExtraDataWidget_un10_orgSportInd" tabindex="21"/></span>
I get the following exception: "'Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException' occurred in Microsoft.VisualStudio.TestTools.UITesting.dll but was not handled in user code"
My code is:
HtmlRadioButton radioButtonObject = new HtmlRadioButton(browserWindow);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Id, radioButtonObjectIDVal, PropertyExpressionOperator.Contains);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Name, radioButtonObjectNameVal, PropertyExpressionOperator.Contains);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Value, "AddExtraDataWidget_un10_No", PropertyExpressionOperator.Contains);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.ControlType, "RadioButton", PropertyExpressionOperator.EqualTo);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Class, "Radio", PropertyExpressionOperator.EqualTo);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Type, "radio", PropertyExpressionOperator.EqualTo);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.ClassName, "HtmlRadioButton", PropertyExpressionOperator.EqualTo);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.TagName, "INPUT", PropertyExpressionOperator.EqualTo);
radioButtonObject.FindMatchingControls();
radioButtonObject.GetClickablePoint();
radioButtonObject.DrawHighlight();
radioButtonObject.Find();
radioButtonObject.EnsureClickable();
Mouse.Click(radioButtonObject);
radioButtonObject.Selected = fieldVal;
I tried almost everything suggested in these forums and MSDN too but no luck.
Can someone help me on this please? Your help would be much appreciated.
Thanks
Less is more usually when searching. If you know the id, you only have to set the id (assuming the ids are actually unique in the page).
HtmlRadioButton radioButtonObject = new HtmlRadioButton(browserWindow);
radioButtonObject.SearchProperties.Add(HtmlRadioButton.PropertyNames.Id, "AddExtraDataWidget_un10_No_GROUP", PropertyExpressionOperator.Equals);
Having the extra search properties only makes the test work harder than it needs to :)
Doing a contains may be dangerous if there are more than one with this partial id. If you need a partial match and know that more than one may be found, use FindMatchingControls() and filter down to the one you want using LINQ or something.
I have an example of finding a hidden control here http://codeduiexamples.com/examples/example1
How is your control being hidden? Eg, display: none, visibility: hidden, removing from DOM, ...?