Trying to get Hex/RGB value of a color preview swatch, please help!
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am surprised that even the Smartbear support team is surprisingly quiet! Does this mean there is no way TestComplete can do this!!?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Robert,
As you suggested, I am using IE 11. Now I am getting runtime error:
TypeError: Cannot read property 'color' of null
var style = page.contentDocument.defaultView.getComputedStyle(colorPrimary, ""); Log.Message(style.background-color);I am not quite sure if I should be using
Log.Message(style.background-color);
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the code that I'm using, I get the element from the page in IE... then I get the "currentStyle.backgroundColor" property. I think that's better than the getComputedStyle method. See if that works better for you.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. I will give it a try.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I used:
var style = page.contentDocument.defaultView.currentStyle.backgroundColor(colorPrimary, "")
as you suggested.
I am getting:
TypeError: Cannot read property 'backgroundColor' of undefined
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
backgroundColor is not a method, it's the actual property. So, just compare that property to the desired value.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Robert
Thank you for the clarification. 🙂
