How to identify color of an img

I have attached a web page, which contains image and colored fonts in a table.

CAR APPLICATION

POC APPLICATION

<table border="1" align="center">
    <tr>
        <th>Name</th>
        <th>Origin</th>
        <th>Status</th>
    </tr>
    <tr>
        <td>Bugatti Veyron Super Sport</td>
        <td><font color="red">Molsheim, Alsace, France</font></td>
                <!-- considering it is on the same folder that .html file -->
        <td><img src="images.png" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td>SSC Ultimate Aero TT  TopSpeed</td>
        <td><font color="blue">United States</td>
        <td><img src="download.jpg" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td>Koenigsegg CCX</td>
        <td><font color="blue">Ängelholm, Sweden</td>
        <td><img src="download.jpg" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td>Saleen S7</td>
        <td><font color="red">Irvine, California, United States</td>
        <td><img src="images.png" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td> McLaren F1</td>
        <td><font color="red">Surrey, England</td>
        <td><img src="images.png" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td>Ferrari Enzo</td>
        <td><font color="red">Maranello, Italy</td>
        <td><img src="images.png" alt="" border=3 height=20 width=20></img></td>
    </tr>
    <tr>
        <td> Pagani Zonda F Clubsport</td>
        <td><font color="blue">Modena, Italy</td>
        <td><img src="download.jpg" alt="" border=3 height=20 width=20></img></td>
    </tr>
</table>

I am able to upload a file so I posted web page sorce code.
plz help me.

Can you share the web address?

i uploaded source code try to open it in browser.

@AmitB - Launch UiExplorer and get selectors for all the different colored boxes.
Compare the selectors. You will have atleast one attribute which will be diff for each box. You can use get attribute activity and find out which type of color it is.

sir can u plz create a sample workflow. that will be very helpfull

@AmitB The idea is - These colored boxes are just images. So, if you look at the code you shared, the sources of red and blue boxes are different images.
So, you can try the below solution :

  1. Use a loop
  2. Inside loop, use get Attribute Activity.
  3. Pass “src” as input Attribute.
  4. Check Output. The output for different colors will be different but same for same colors.
  5. If output is “xyz/download.jpg” then color is blue. If it “xyz/images.jpg” then color is red. These values (download and images I got from your code)

2 Likes

You can use JavaScript to do this. See a sample below.

var redText = 'red';
var blueText = 'blue';
var redCount = 0;
var blueCount = 0;
var fontTags = document.getElementsByTagName('font');
for (let index = 0; index < fontTags.length; index++) {
  const colorValue = fontTags[index].getAttribute("color");
  if (colorValue == redText) redCount ++;
  if (colorValue == blueText) blueCount++;
}

var obj = {
    red : redCount,
    blue : blueCount
}

console.log(redCount);
console.log(blueCount);
console.log(JSON.stringify(obj));

I tried this in for each loop (data scrappng) and try to increment the counter but counter values are not incrementing.

Right now this is my workflow.

Hi @AmitB - I am attaching a workflow which you can try.
Follow below steps :

  1. Open the webpage in IE
  2. For find children activity - Indicate the whole table
  3. Run the workflow
  4. Check the output of Writeline activity
  5. Change the values in case (of switch activity)

Main.xaml (7.4 KB)

Thanks @mahesh.kumar and @KannanSuresh for reply. I got my answer.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.