Forum Discussion

Test56's avatar
Test56
Contributor
11 years ago
Solved

Retrieving CSS property

Hello,



I am using TC 9.3 version. I need to retrieve the web objects CSS properties. I am trying to retrieve it as a property of the web object,

e.g. "aqObject.GetPropertyValue(webObject, propertySpecified)" where propertySpecified was mentioned as "style.fontSize". But this didn't returned anything. Can you please suggest how we can retrieve the values. I am using VB scripting.
  • There is sample code here: http://support.smartbear.com/viewarticle/62849/, but there is element variable missing in the IE 7-8 code path, so the correct code should be like that:



    Function getStyle(element, styleProp)

      Dim document, style

      Set document = element.ownerDocument



      If aqObject.IsSupported(document, "defaultView") Then

        ' Internet Explorer 9+, Firefox, Chrome, Safari, Opera

        Set style = document.defaultView.getComputedStyle(element, "")

        getStyle = style.getPropertyValue(styleProp)

      Else

        ' Internet Explorer 7 - 8

        getStyle = element.currentStyle.getPropertyValue(styleProp)

      End If

    End Function



    When calling it you should not use "style." in styleProp parameter, just "fontSize" or some other property name.

4 Replies

  • There is sample code here: http://support.smartbear.com/viewarticle/62849/, but there is element variable missing in the IE 7-8 code path, so the correct code should be like that:



    Function getStyle(element, styleProp)

      Dim document, style

      Set document = element.ownerDocument



      If aqObject.IsSupported(document, "defaultView") Then

        ' Internet Explorer 9+, Firefox, Chrome, Safari, Opera

        Set style = document.defaultView.getComputedStyle(element, "")

        getStyle = style.getPropertyValue(styleProp)

      Else

        ' Internet Explorer 7 - 8

        getStyle = element.currentStyle.getPropertyValue(styleProp)

      End If

    End Function



    When calling it you should not use "style." in styleProp parameter, just "fontSize" or some other property name.
  • Thanks for the reply. I had tried this already but

    Set style = document.defaultView.getComputedStyle(element, "")

    is giving me error telling document doesn't support defaultView call. Do we have any other option to work ?
  • What web browser version are you using?



    BTW, instead of "fontSize" in the call to getStyle function you should use not JavaScript but CSS names, like "font-size".
  • Thanks it worked fine, There was a confusion for IE version in my system.