Forum Discussion

royd's avatar
royd
Regular Contributor
6 years ago

Trying to get Hex/RGB value of a color preview swatch, please help!

Hi everyone

 

In configuration page some colors are customizable. 

  • When clicked on any of the input fields, a color chooser pops up.
  • Selecting a color populates the field with the hex value.
  • The preview swatch updates to the selected color.

I am trying to access the hex value of the preview color. After some reading, this is what I came up with:

(I have noticed that swatch value shows up as Hex in Chrome but as RGB in IE!)

 

  var colorPrimary = page.QuerySelector(".evo-colorind");
  var style = page.contentDocument.defaultView.getComputedStyle(colorPrimary, "");
  Log.Message(style.background-color);

 

 

 

I am getting JavaScript runtime error 0x80020101 at 'style' var. Any help deeply appreciated.

  • backgroundColor is not a method, it's the actual property.   So, just compare that property to the desired value.

     

     

    • royd's avatar
      royd
      Regular Contributor

      Hi Rudolph

       

      Thanks for the link. This will help me understand what I am doing wrong.

       

      Thanks. :)

      • RUDOLF_BOTHMA's avatar
        RUDOLF_BOTHMA
        Community Hero

        Glad it could help

         

        What stood out to me is that it appears the style they are picking up is "backgroundColor" rather than "background-color"

  • royd's avatar
    royd
    Regular Contributor

    I am surprised that even the Smartbear support team is surprisingly quiet! Does this mean there is no way TestComplete can do this!!?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Actually, I think the difference is beyond even just whether or not it shows as RGB versus Hex...  I have a checkpoint set up that does something similar.... but the caveat that I have is that it will work with IE only.  I think the contentDocument property/object or some of the methods and properties of it are only available in IE.  That would be where I'd start, to put a breakpoint on that line and do some investigation as to why JavaScript is burping there... 

      • royd's avatar
        royd
        Regular Contributor

        Thanks Robert!

         

        You are always there when I need help!  I almost gave up hope. I will give it a try tomorrow and let you know.

         

        Dave