The other day while automating a test case for our Web application I found that SWEA was recognizing that an element existed on the page even though I couldn’t see it. This wasn’t good because that element was a client side error message for a form and nothing was being done with the form to throw the error. A closer look at the HTML revealed a <SPAN> tag with the style property visibility set to “hidden”. It looked like this:
<span style=’visibility:hidden’ class=’VAMErrorText’ id=’valInactiveDays’><span id=’valInactiveDays_Txt’>Must enter a numeric value.</span>
A test case that actually caused the error to visually appear on the page resulted in the following change to the HTML:
<span style=’visibility:visible class=’VAMErrorText’ id=’valInactiveDays’><span id=’valInactiveDays_Txt’>Must enter a numeric value.</span>
So, in the top example the element existed in SWEA’s eyes because it existed on the page but it was “hidden”. My problem to solve was how to make my test acknowledge that the error message wasn’t really thrown and that it was still “hidden”. At the time I figured it would be best to extract the HTML out of the SWEA control and search for the text “Visibility:hidden”. My resolution looked like this:
When talking to Alex after the fact, he reminded me that I could also pull out the Style information by doing the following:
((HtmlContent)(myBrowser.Scene[“HiddenVAMLbl”])).Invoke (“Get_Style”).ToString().IndexOf(txtHidden) > -1;
A little less elegant but either way solves my problem.