Nimeshika
11 years agoContributor
How to validate the color of single line in text object
Hello,
I have a TextBlockClass , System.Windows.Controls.TextBlock where only the heading line is in Bold Red. Rest of the text is in normal black font. I want to validate that the header is is in bold red. I could not spy only the header text. When i used text recognition I was able to spy the entire text block but not the heading line seperately.
I tried foreground property but was not clear on that kind of validation.
Can someone help me in how i can validate that the heading is in bold red in the textBlock?
I have a TextBlockClass , System.Windows.Controls.TextBlock where only the heading line is in Bold Red. Rest of the text is in normal black font. I want to validate that the header is is in bold red. I could not spy only the header text. When i used text recognition I was able to spy the entire text block but not the heading line seperately.
I tried foreground property but was not clear on that kind of validation.
Can someone help me in how i can validate that the heading is in bold red in the textBlock?
Hi Nimeshika,
There should be separate objects for TextBlock text lines even if they're not spyable. Check TextBlock's child objects in the Object Browser - you should see something like this:
Once you find the needed object, you can check its FontWeight and Foreground.Color properties to verify the style. Here's an example:// JScript
function Test()
{
var header = ...; // "Path" to your header object
// Check the font weight
var strFontWeigth = header.FontWeight.ToString().OleValue;
if (strFontWeigth == "Bold")
{
Log.Checkpoint("The header is in Bold.");
}
else
{
Log.Error("The header is not in Bold; it's " + strFontWeigth);
}
// Check the font color
var strColor = header.Foreground.Color.ToString().OleValue;
if (strColor == "#FFFF0000")
{
Log.Checkpoint("The header is red.");
}
else
{
Log.Error("The header is not red (#FFFF0000); it's " + strColor);
}
}