Forum Discussion

mtrampe's avatar
mtrampe
Occasional Contributor
13 years ago

How can TestComplete identify if a text is italic, bold or underlined

I need to check if the a text displayed in a webpage is in italic, bold or underlined. unfortunately there are no property that i can use. 



Can anyone help me how?



Thanks,

Mike

1 Reply

  • You can check it after obtaining current style of page element: font-style for italic, font-weight for bold and text-decoration for underline.

    In Internet Explorer every page element has currentStyle property. In other browsers (as well as IE 9+) page object has contentDocument.defaultView.getComputedStyle function to get current style for a web page element.



    function getCurrentStyle(page, webobj, propName)

    {

      var style = page.contentDocument.defaultView.getComputedStyle(webobj, "");

      return style.getPropertyValue(propName);

    }



    function test()

    {

      var page = Sys.Browser("*").Page("*");

      Log.Message(getCurrentStyle(page, page.Child(0), "font-style"));

    }