Ask a Question

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

SOLVED
royd
Regular Contributor

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);

 

error 0x80020101.png

 

 

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

17 REPLIES 17
TanyaYatskovska
SmartBear Alumni (Retired)

Hi @royd,

 

Could you please mark the answer that help you as a solution? You see a big green "Accept as Solution" button next to it. It will help other community members who will face a similar situation. Thanks.

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



RUDOLF_BOTHMA
Community Hero

While I was searching for something else I happened upon something and thought it might be of assistance to you.  The smartbear support for handling browser differences has a secion about attribute values that looks specifically at how to handle the background color in different browsers as an example

https://support.smartbear.com/testcomplete/docs/app-testing/web/general/cross-browser/handling-diffe...

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
royd
Regular Contributor

Hi Rudolph

 

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

 

Thanks. 🙂

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"


-------------------------------------------------
Standard syntax disclaimers apply
Regards,
royd
Regular Contributor

Hi Tanya

 

I always do, when I have found a solution! 

 

I  would like to take the opportunity to point out, that the users are always there to help, more than support people. Especially Robert has always been there and help solve 95% of my problems!! I can not thank him and all other experts that have helped me.

royd
Regular Contributor

Hi Robert

 

Sorry for delayed response. It took me a while but finally figured it out. Thanks for pointing me to right direction. This is what finally worked:

 

var previewColor =  previewSwatch.ownerDocument.defaultView.getComputedStyle(previewSwatch, "").backgroundColor;
TanyaYatskovska
SmartBear Alumni (Retired)

Hi @royd.

 

I'm so glad to hear that the solution has been found 🙂

---------
Tanya Yatskovskaya
SmartBear Community and Education Manager



color_value=Aliases.browser.page.{object_name}.getAttribute('fill')

Log.Message(color_value)

color_value has "#e1542b", I have to convert hexcode to rgb inorder to verify rgb color value, as have a color file where I stored the list of colour name according to rgb values. 

Kindly help on this. 

cancel
Showing results for 
Search instead for 
Did you mean: