The item selected will have white color text with blue background and the item that is not selected will have black color text with white background color.
I need to verify whether the item is selected already. If not selected already, i should select it.
Do we have anything to select the text based on the color
i tried the following code. but it selects text with both the colors black and white. need your suggestions
The easiest way to do this is going to be with a captured image. This will verify the state of the text. You could create an image collection containing images of the text in both states, and then depending on which image in the collection is found, you could execute a different action, to select it or not.
To read about how to create an image collection please see this page: http://docs.testplant.com/?q=content/creating-image-collection
The code you said you tried is not going to work, because you are using a TIG (Text Image Generator) parameter with an OCR (Optical Character Recognition) search. You can specify to use Contrast, and also set a ContrastColor with the OCR search, but this is to help it eliminate anti-aliasing in its search, and does not function the same way as the TIG setting. Feel free to play around with these settings and see which works best for you in your situation. You can read more about using the OCR here: http://docs.testplant.com/?q=content/working-ocr
If you have further questions on this, please feel free to write in to TestPlant support with your question and we’ll help you work on specifics related to your situation. Thanks!
I know it’s very old post. Just checking incase if anyone can support.
@Allwin@eggElizabeth Anyone have a solution for this. I am struggling to check if a text, button or link is disabled or enabled. In my case, background always the same, only the text color differs.
To select text based on color in eggplant, use an image collection to capture text in both selected and unselected states. Mixing TIG and OCR won’t work. Adjust OCR settings like contrast and contrast color for better results. Refer to the eggplant documentation for detailed steps.
I would suggest one of these approaches:
If the text is always the same, but can appear in 2 (or more) different colors, capture an image for each color and then just check which image is found on the screen. When working with text, people tend to forget about using images and want to use OCR, but there are times when an image is the simpler solution.
If the text may vary so capturing images is impractical, you could search for the text in a particular color by setting that as the contrast color. By doing that, text in that color should be “visible” to the engine, and text in other colors won’t. So (with the proper tweaks to the contrast settings) that should allow you to read (or find) the text or not depending on whether it is visible in the enabled or disabled color.