How to get the font color of a JTree item using Javascript
- 4 years ago
Hi jmoe.
One option is to take a picture of the JTree Item and compare it to a static image. I assume that the JTree Item has a picture function. If not the parent window might have the function. If that isn’t the case you could position the window in a specific location and take a picture of the screen.You could also try taking a picture and compare the pixel(s) color. I am not sure what language you are programming in, but below is an example that will take a picture and compare the first pixel to a desired constant color. I have not tried any of this code, but it should give you some direction. I hope this helps.
function comparePixel()
{
// take a picture at the specified location with a width and height of 1
var pic = jTreeItem.Picture(desiredLeftPosition, desiredTopPosition, 1, 1);
// compare to the desired color
if (pic.Pixels(0,0) == clMenuText) // color values can be found here: https://support.smartbear.com/testcomplete/docs/scripting/colors.html
{
// whatever you need to do....
}
}
A more detailed explanation for others...
function comparePixel()
{
var parentControl = Aliases.Product; // the parent control could be a window if searching for a control like a textbox
// use the correct property names for your window or control
var propNames = new Array(propName1, propName2);
// use the correct property values for your window or control
var propValues = new Array(propValue1, propValue2);
// specify a search depth.
var depth = 100;
// find the window/control from the parent
var control = parentControl.FindChild(propNames, propValues, depth);
// made up number use your distance to the desired left position
var x = 10;
// made up number use your distance to the desired top position
var y = 10;
// 1, 1 is the width and height of the image
var pic = control.Picture(x, y, 1, 1);
// use this to get the constant color value if you don't know what that value is...otherwise it can be commented out...
var color = pic.Pixels(0,0);
// color values can be found here: https://support.smartbear.com/testcomplete/docs/scripting/colors.html
// if it is a custom color you can see an example function at the above link that will allow R,G,B comparison
// specify the color you want to compare
if (pic.Pixels(0,0) == clRed)
{
// whatever you need to do....
}
}