Disabled item in combobox throwing exception - control not available.

Mar 27, 2013 at 3:30 PM
Hello,

I have a combobox with 4 items in it. One of the items has a disabled = disabled tag set on it. Here is the HTML:
<select id="acctActions20714" onchange="Navigate($('#acctActions20714').val() ,20714, 1, 'Visa', '', '2220', 'Non-Recurring')" name="acctActions20714">
<option value="">Available Actions...</option>
<option value="MakePayment" disabled="disabled">Make Payment</option>
<option value="ViewPaymentAcct">View Account Detail</option>
<option value="ActivatePaymentAcct">Activate Account</option>
</select>
When the automation tries to do anything with that disabled option I get the following exception (see below). For instance, I want to get the InnerText from the control - "Make Payemnt" but I get the error.

If I remove the disabled tag then the automation can access the Option without any problem.

Has anyone seen this before? Is there a way to get around this?

Thanks

Jeff

EXCEPTION:
System.Exception: Test failed on step 1 - iteration 1. ---> Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException: The control is not available or not valid. Additional Details:
TechnologyName: 'Web'
ControlType: 'ListItem'
Id: ''
Name: ''
TagName: 'OPTION'
InnerText: 'Make Payment'
---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
Mar 29, 2013 at 8:47 PM
I had this same issue, but have yet to find a good solution.

Referencing the object and trying to access it's Items often times out as well.
var dropdown = Get<CUITe_HtmlComboBox>("id~acctActions")
dropdown.Items //times out on evaluation 
dropdown.ItemCount //times out on evaluation
Any advice is appreciated.
Thanks,
`Pat
Coordinator
Mar 30, 2013 at 11:03 PM
Hi Jeff and Pat,

If your html <select/> element has the multiple attribute set, then CUITe_HtmlList should be used.

Otherwise, CUITe_HtmlComboBox should be used.

I hope that resolves your problem.

If not, please paste the sample html and the coded ui test code.

Thank you.

Here is a test method that works without issues:
        [TestMethod]
        public void InnerText_OnHtmlComboBoxWithDisabledItems_Succeeds()
        {
            //Arrange
            using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option value=""1"">1</option>
            <option value=""2"" disabled=""disabled"">2</option>
            <option value=""3"" disabled=""disabled"">3</option>
        </select>
    </body>
</html>"))
            {
                CUITe_BrowserWindow.Launch(tempFile.FilePath);
                CUITe_BrowserWindow window = new CUITe_BrowserWindow("test");

                CUITe_HtmlComboBox comboBox = window.Get<CUITe_HtmlComboBox>("Id=selectId");
                
                //Assert
                Assert.AreEqual("1 2 3 ", comboBox.InnerText);

                window.Close();
            }
        }
Coordinator
Mar 30, 2013 at 11:26 PM
Thanks Pat,

I just checked in an update (changeset #25213) to the Items and and ItemCount properties of the CUITe_HtmlList and CUITe_HtmlComboBox controls to resolve the issues you experienced.
        [TestMethod]
        public void InnerText_OnHtmlComboBoxWithDisabledItems_Succeeds()
        {
            //Arrange
            using (TempFile tempFile = new TempFile(
@"<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <select id=""selectId"">
            <option value=""1"">1</option>
            <option value=""2"" disabled=""disabled"">2</option>
            <option value=""3"" disabled=""disabled"">3</option>
        </select>
    </body>
</html>"))
            {
                CUITe_BrowserWindow.Launch(tempFile.FilePath);
                CUITe_BrowserWindow window = new CUITe_BrowserWindow("test");

                CUITe_HtmlComboBox comboBox = window.Get<CUITe_HtmlComboBox>("Id=selectId");
                
                //Assert
                Assert.AreEqual(3, comboBox.ItemCount);
                CollectionAssert.AreEqual(new string[] { "1", "2", "3" }, comboBox.Items);
                Assert.AreEqual("1 2 3 ", comboBox.InnerText);

                window.Close();
            }
        }