cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving CSS property

SOLVED
Highlighted
Contributor

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.
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Staff

RE: Retrieving CSS property

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.

View solution in original post

4 REPLIES 4
Highlighted
Staff

RE: Retrieving CSS property

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.

View solution in original post

Highlighted
Contributor

RE: Retrieving CSS property

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 ?
Highlighted
Staff

RE: Retrieving CSS property

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".
Highlighted
Contributor

RE: Retrieving CSS property

Thanks it worked fine, There was a confusion for IE version in my system.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors