title: coded ui test project, obtain value of asp label
body: <p>Created a simple calculator app in webforms.
  User enters a number in a text field <code>MainContent_numberTb</code> and clicks on results button. </p>
  
  <p>Added a new 'coded UI Test Project' to my solution. Have tested the UI by adding '5', This all works fine. Would now like to compare the actual result against the expected result.</p>
  
  <pre><code>BrowserWindow Browser = BrowserWindow.Launch("http://url");
  
  UITestControl UiInputField = new UITestControl(Browser);
  UiInputField.TechnologyName = "Web";
  UiInputField.SearchProperties.Add("ControlType", "Edit");
  UiInputField.SearchProperties.Add("Id", "MainContent_numberTb");
  
  //Populate input field
  Keyboard.SendKeys(UiInputField, "5");
  
  //Results Button
  UITestControl ResultsBtn = new UITestControl(Browser);
  ResultsBtn.TechnologyName = "Web";
  ResultsBtn.SearchProperties.Add("ControlType", "Button");
  ResultsBtn.SearchProperties.Add("Id", "MainContent_calBtn");
  
  Mouse.Click(ResultsBtn);
  </code></pre>
  
  <p>All above code works fine, problem occurs when trying to access the label</p>
  
  <pre><code>&lt;asp:Label ID="AllNumLbl_Res" runat="server"&gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>What do I insert beside control type? It's not edit as edit is the text field. Then also, what stores the actual result so I can compare <code>AllNumsTB</code>?</p>
  
  <pre><code>string expectedAllNums = "1, 2, 3, 4, 5";
  UITestControl AllNumsTB = new UITestControl(Browser);
  AllNumsTB.TechnologyName = "Web";
  AllNumsTB.SearchProperties.Add("ControlType", "?????");
  AllNumsTB.SearchProperties.Add("Id", "MainContent_AllNumLbl_Res");
  
  if(expectedAllNums != AllNumsTB.??????)
  {
      Assert.Fail("Wrong Answer");
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  OK so using the debugger console I was able to get the value of the label using <code>((Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlSpan)new System.Collections.ArrayList.ArrayListDebugView(((System.Collections.CollectionBase)(AllNumsTB.FindMatchingControls()).List).InnerList).Items[0]).DisplayText</code></p>
  
  <p>but when I use this in the code &amp; <code>ArrayListDebugView</code> are inaccessible due to protection??</p>
  
  <p>//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  <strong>UPDATE</strong>
  Thanks K Scandrett for the answer...If I may I was wondering could you also please help me with the validation...If the user enters a letter or a non positive number the error message will fire..</p>
  
  <pre><code>&lt;asp:RegularExpressionValidator ID="regexpName"
  
   //VALIDATION MESSAGE
                  UITestControl PositiveNumValMsg = new UITestControl(Browser);
                  PositiveNumValMsg.TechnologyName = "Web";
                  PositiveNumValMsg.SearchProperties.Add("Id", "MainContent_regexpName");
  </code></pre>
  
  <p>This all works fine, however I want to test if the label appears or not...so far I have tried</p>
  
  <pre><code>//bool visible = false;
              //System.Drawing.Point p;
  
              //// If the control is offscreen, bring it into the viewport
              //PositiveNumValMsg.EnsureClickable();
  
              //    // Now check the coordinates of the clickable point
              //    visible = PositiveNumValMsg.TryGetClickablePoint(out p)
              //        &amp;&amp; (p.X &gt; 0 || p.Y &gt; 0);
  
              var isVisible = PositiveNumValMsg.WaitForControlPropertyNotEqual(UITestControl.PropertyNames.State, ControlStates.Invisible);
  </code></pre>
  
  <p>but they all return true even when the label is not shown, but it is still on the page just set to invisible. In that case I should check its style..something like </p>
  
  <pre><code>//string labelText3 = PositiveNumValMsg.GetProperty("style").ToString();
  </code></pre>
  
  <p>then check if the style contains <code>visibility: visible</code>?</p>