Forum Discussion

jsc's avatar
jsc
Regular Contributor
10 years ago

Chrome: window.getcomputedvalue in scriptextensions

Hey all,   I need to check a computed css value. When I use the console of chrome the function is like this: window.getcomputedvalue(document.getelementbyid('UiMask').opacity)   I was not able ...
  • HKosova's avatar
    10 years ago

    Hi Joachim,

    In script extensions, you need to address web pages as Sys.Browser().Page(url). From there, you can access the document object as .contentDocument, and the window object as .contentDocument.defaultView or .contentDocument.parentWindow (in IE).

    To get computed CSS styles, we recommend using the cross-browser getStyle function from the TestComplete documentation:

    http://support.smartbear.com/viewarticle/62849/#Example


    So, your code should be something like this:

    var element = Sys.Browser().Page(...).contentDocument.getElementById("UiMask");
    var opacity = getStyle(element, "opacity");


    function getStyle(element, styleProp) { var document = element.ownerDocument; if (aqObject.IsSupported(document, "defaultView")) { // Internet Explorer 9+, Firefox, Chrome, Opera var style = document.defaultView.getComputedStyle(element, ""); return style[styleProp]; } else { // Internet Explorer 7 - 8 return element.currentStyle[styleProp]; } }