Disabled Checkboxes not accessable

Sep 14, 2012 at 8:26 AM
Edited Sep 14, 2012 at 8:27 AM

Hi

I have a table which contains multiple disabled checkboxes, indicating a certain state.

Now, when I try to access this checkboxes and check for theire status (checked or unchecked), I get an Exception that indicates its inaccessable.

Is there a possibility to access them?

Here a sample of the html code, containing the checkbox.

<span class="aspNetDisabled">
  <input id="DetailContent_gvCD34_cbBMA1_5" disabled="disabled" name="ctl00$DetailContent$gvCD34$ctl08$cbBMA1" CHECKED="checked" type="checkbox">
</span>                    

Thanks for the help in advance

Floopy-Doo

Coordinator
Sep 15, 2012 at 1:10 AM

Hi Floopy-Doo,

I could not reproduce the issue.

I just checked in a sample unit test:

<input type="checkbox" id="checkBox1" disabled="disabled" name="checkBox1" checked="checked" />

        [TestMethod]
        public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState()
        {
            CUITe_BrowserWindow bWin = CUITe_BrowserWindow.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

            CUITe_HtmlCheckBox chkBox1 = bWin.Get<CUITe_HtmlCheckBox>("id=checkBox1");

            Assert.IsTrue(chkBox1.Exists);
            Assert.IsTrue(chkBox1.Checked);

            bWin.Close();
        }

What is the exception thrown in your case?

        [TestMethod]
        public void HtmlCheckBox_DisabledByStyle_ControlExistsAndCanGetCheckedState()
        {
            CUITe_BrowserWindow bWin = CUITe_BrowserWindow.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

            CUITe_HtmlCheckBox chkBox1 = bWin.Get<CUITe_HtmlCheckBox>("id=checkBox1");

            Assert.IsTrue(chkBox1.Exists);
            Assert.IsTrue(chkBox1.Checked);

            bWin.Close();
        }
Sep 17, 2012 at 9:38 AM
Edited Sep 17, 2012 at 10:58 AM

Hi icnocop

I tried the test case and I coudn't reproduce the issue as well. I use an modified version of the changeset 19632.

As I mentioned earlier the disabled CheckBox is inside a table. I wrote a method to get the controls of a cell. This method is located in the CUITe_HtmlTable class.

 

        public List<ICUITe_ControlBase> GetCellChildrens(int iRow, int iColumn)
        {
            List<ICUITe_ControlBase> controls = new List<ICUITe_ControlBase>();

            foreach (HtmlControl ctrl in this.GetCell(iRow, iColumn).GetChildren().OfType<HtmlControl>())
            {
                controls.Add(base.WrapUtil(ctrl));
            }

            return controls;
        }

 

And then when I try to get the CheckBox inside the Span element, like this:

 

         var ctrl1 = page.tblCD34Liste.Get<CUITe_HtmlCheckBox>("Id=DetailContent_gvCD34_cbBMA1_" + row);
         Assert.IsFalse(ctrl1.Enabled);
         var rowCtrls= page.tblCD34Liste.GetCellChildrens(row, 16);
         var ctrl2= rowCtrls[0].GetChildren()[0];
         Assert.IsFalse(ctrl2.Enabled);

 

I get an exception when I try to access the "ctrl2" control. The exception:

 

The control is not available or not valid. Additional Details: 
TechnologyName:  'Web'
ControlType:  'CheckBox'
Id:  'DetailContent_gvCD34_cbBMA1_0'
Name:  'ctl00$DetailContent$gvCD34$ctl03$cbBMA1'
TagName:  'INPUT'

 

Here the HTML from the table cell content:

 

<span class="aspNetDisabled">
   <input id="DetailContent_gvCD34_cbBMA1_0" disabled="disabled" name="ctl00$DetailContent$gvCD34$ctl03$cbBMA1" CHECKED="checked" type="checkbox">
</span>                    

 

I hope I provide enough data.

Thanks Floopy-Doo

Coordinator
Sep 17, 2012 at 10:16 AM

Hi Floopy-Doo,

I am wondering what is the value of 'ctrl' in this line of the sample code:

var ctrl2= ctrl[0].GetChildren()[0];

Should it be this instead?

var ctrl2= rowCtrl[0].GetChildren()[0];

 

I also recommend the following:

1. Use explicitly typed variables instead of 'var' unless you are really using an anonymous type

2. Limit the number of assumptions the code is doing.  For example, make sure ctrl[0] or rowCtrl[0] contain the data expected before trying to access its children.

 

Have you modified any playback settings?

It may be related to an issue where controls are being accessed that no longer exist (only cached).

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitest.extension.uitestcontrolnotavailableexception.aspx

Are you trying to test across IE tabs?

Also see these links:

http://forums.asp.net/t/1663375.aspx/1

http://social.msdn.microsoft.com/Forums/pl-PL/vsautotest/thread/6694a577-6ba0-4472-8c5b-bfb126e55c68

Is the Visual Studio Coded UI Test Recorder able to record and playback the test without issue?

Does this happen for all controls on the page or just the checkbox control?

Have you tried to clear your browser cookies before running the test?

Does the Coded UI trace log contain any more information?

http://blogs.msdn.com/b/gautamg/archive/2009/11/29/how-to-enable-tracing-for-ui-test-components.aspx

Sep 17, 2012 at 10:57 AM

Hi

Sorry, I altered the code for better readability but I missed this. (already edited this in the post)

I just written the code for test purposes for this issue, so its not very clean (using of "var" and no checks for null).

 

The playback settings are modified. I used the SmartMatchOptions.None for all the test cases.

 

No, I don't test across tabs.

 

I Haven't tried the Object Recorder for this case.

 

No, only for this checkbox.

Coordinator
Sep 17, 2012 at 5:31 PM

please try closing the input tag

Sep 18, 2012 at 2:56 PM
Edited Sep 18, 2012 at 2:56 PM
icnocop wrote:

please try closing the input tag

Unfortunately its ASP.Net generated HTML code.

Coordinator
Sep 18, 2012 at 5:29 PM

What version of ASP.Net are you using?

Are you using an HtmlInputCheckBox control?

How is the control defined?

Sep 20, 2012 at 1:14 PM
Edited Sep 20, 2012 at 1:15 PM
icnocop wrote:

What version of ASP.Net are you using?

Are you using an HtmlInputCheckBox control?

How is the control defined?

1) .Net v4.0.30319.

2/3) the control is defined inside the template field of a grid view control.

 

<asp:TemplateField>
   <ItemTemplate>
      <asp:CheckBox ID="cbBMA1" runat="server" Enabled="false" />
   </ItemTemplate>
</asp:TemplateField>

Thanks for all the help so far.

Coordinator
Sep 20, 2012 at 9:11 PM

Hi Floopy-Doo,

Please try my previous suggestions:

> Is the Visual Studio Coded UI Test Recorder able to record and playback the test without issue?

> Have you tried to clear your browser cookies before running the test?

> Does the Coded UI trace log contain any more information?

> http://blogs.msdn.com/b/gautamg/archive/2009/11/29/how-to-enable-tracing-for-ui-test-components.aspx