This project is read-only.

How to validate the control based on Style?

Jul 10, 2012 at 7:47 PM

I have two control on my web page.

<tr id="FCYear2" style="display: inline; background-color: rgb(234, 234, 234);">

<tr id="FCYear3" style="display: none;">

First control "FCYears2" shows up on the webpage. The second one "FCYear3" is not displayed on page.  

I have to validate the above controls display. I wrote below  




First assertion is passed. Second assertion is failed. How can we validate the control existence based on the style or any other way ? Appreciate your hep in this ?



Jul 11, 2012 at 9:24 PM

Hi Sailaja,

There is a sample unit test that illustrates how to use the Exists property for invalid controls.


public void Test_InvalidControlExists()
    Playback.PlaybackSettings.SmartMatchOptions = SmartMatchOptions.None; //required if you are using .Exists on an invalid control
    GoogleHomePage pgGHomePage = CUITe_BrowserWindow.GetBrowserWindow();

Jul 12, 2012 at 8:49 PM


Thank you for quick response.  I tried the above sample code.  Throwing me an compilation error  "SmartMatchOptions" doesnot exist in current context. What could be reason? Am I missing anything? Appreciate your help.




Jul 12, 2012 at 9:16 PM

You are probably missing a project reference and using statement for Microsoft.VisualStudio.TestTools.UITest.Extension:

HintPath: c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.TestTools.UITest.Extension.dll



SmartMatchOptions Enumeration

Jul 13, 2012 at 5:50 PM

Yes, I missed the reference. I added that.  Still the asserts are failing. When i looked at the view source both the controls exist, but the only diffrence is style attribute. Is there any other way that we can validate invalid control on the page. Appreciate your help. Thanks,

<tr id="FCYear2" style="display: inline; background-color: rgb(234, 234, 234);">

<tr id="FCYear3" style="display: none;">

Jul 14, 2012 at 3:01 AM
Edited Jul 14, 2012 at 3:03 AM

I just checked in a sample unit test in Sample_CUITeTestProject

From TestHtmlPage.html:


<button id="hiddenButton" style="display: none;" />


From Tests_for_HtmlControls.cs:


public void HtmlButton_HiddenByStyle_ControlExistsAndCanAssertOnStyle()
    CUITe_BrowserWindow bWin = CUITe_BrowserWindow.Launch(CurrentDirectory + "/TestHtmlPage.html", "A Test");

    CUITe_HtmlButton btnHiddenButton = bWin.Get("id=hiddenButton");


    Assert.IsTrue(btnHiddenButton.UnWrap().ControlDefinition.Contains("style=\"DISPLAY: none\""));