Image Recognition Is Only Finding Image Sometimes...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Image Recognition Is Only Finding Image Sometimes...

Post by rjw524 » Tue Apr 04, 2023 5:12 pm

Hi All,

I am working in an online CRM that uses dynamically generated pages containing javascript.

When I click on a customer's name it opens that customer's record with our company.

One of the tabs on the record page is "Recent Activities".

When I click on the Recent Activities tab a table with information generated using javascript comes up.

Sometimes the table generated can contain anything from 1 line to 20 lines, etc.

To the LEFT of each record is a Reddish colored "Edit" image.

THIS is where the problem begins:

I created a script that finds each of these Edit images in the table and opens a page and scrapes data.

Thanks to Dorian, this script works fine.

The problem now is that each time the table generates and the macro starts over it can't find the Reddish Edit button even though it appears in the EXACT same place. The table ALWAYS generates in the same place.

To the naked eye the Edit button appears exactly the same.

-I have used MDL>%RedFound% to see what the count is and even though there are obviously a number of Edit images on the screen the MDL comes back with "0".
-I have used delays to let to give the script more time to look at the page.
-I have defined a smaller rectangle for the script to focus on in case there were too many similar images confusing it. Still nothing.
-I have used the Image Recognition Wizard to capture the image again and it still doesn't find it.

If anyone has encountered this issue before or knows how to solve it I would appreciate the help.

I have included my script below.

Thanks,

rjw524

Code: Select all

//FIND RED EDIT IMAGES

ScreenCapture>39,536,462,1006,%TEMP_DIR%\screenrect.bmp
//Find and Left Click Center of
FindImagePos>%BMP_DIR%\image_41.bmp,%TEMP_DIR%\screenrect.bmp,0.7,1,XRed,YRed,RedFound,EXACT
Wait 2.0
If>RedFound=0
Wait 1.0
Goto FindEdit
  MouseMove>{%XRed_0%+39},{%YRed_0%+536}
  LClick
Else
wait>1.0
 Let>k=0
 Repeat>k
  Wait 0.1
  MouseMove>{%XRed_0%+39},{%YRed_0%+536}
  wait 0.1
    GetCursorPos>X,Y
    wait 0.1
  MouseMove>{%X%-25},{%Y%+0}
  wait 0.1
  LDown
  wait 0.1
  GetCursorPos>X,Y
  Wait 0.1
  MouseMove>{%X%+1630},{%Y%+0}
  wait 0.1
  LUp
  wait 0.1
  Press CTRL
  Send c
  Release CTRL

  wait 0.1
  LClick
  Wait 0.1

  GetCursorPos>X,Y
  MouseMove>{%X%-1605},{%Y%+0}

  wait>0.1

//PASTE ACTIVITY IN EXCEL

  SetFocus>Excel*
    
    Wait 0.1
    Press CTRL
    Send v
    Release CTRL
    
    wait 0.1

    SetFocus>Microsoft​ Edge*
    Wait 1.0
    
  Let>k=k+1
  Until>k={%RedFound%}
EndIf

Wait 1.0


User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Image Recognition Is Only Finding Image Sometimes...

Post by Dorian (MJT support) » Tue Apr 04, 2023 6:10 pm

It's odd that it found them before, but isn't now. Ordinarily that would suggest the images have changed very slightly (particularly as you're using EXACT) and the advice would be to re-sample the images - but you've already done that.

If RedFound is always 0, try experimenting with increasing the tolerance from 0.7. You can find an explanation of that here.

This is of course if you're 100% sure the images are at the correct position you have specified in ScreenCapture, and if those images are actually visible.

You could also try looking for the images in a specified window instead of a screen area.
Yes, we have a Custom Scripting Service. Message me or go here

rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Re: Image Recognition Is Only Finding Image Sometimes...

Post by rjw524 » Tue Apr 04, 2023 6:27 pm

Dorian (MJT support) wrote:
Tue Apr 04, 2023 6:10 pm
It's odd that it found them before, but isn't now. Ordinarily that would suggest the images have changed very slightly (particularly as you're using EXACT) and the advice would be to re-sample the images - but you've already done that.

If RedFound is always 0, try experimenting with increasing the tolerance from 0.7. You can find an explanation of that here.

This is of course if you're 100% sure the images are at the correct position you have specified in ScreenCapture, and if those images are actually visible.

You could also try looking for the images in a specified window instead of a screen area.
Thanks for getting back to me so quickly! I'm doing this for work so it's very appreciated!

Yes, I have to re-sample the image each time I open a new customer record. I've been using MS and Image Recognition enough over the years to know it's NOT wrong. The image HAS to be changing ever so slightly.

Yes, the images are completely visible and in the same positions.

So let me ask...I thought I could only increase the tolerance with CCOEFF? That works for EXACT as well? Because the script has to click on image in the array.

Thanks!

rjw524

User avatar
Grovkillen
Automation Wizard
Posts: 1128
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Image Recognition Is Only Finding Image Sometimes...

Post by Grovkillen » Tue Apr 04, 2023 6:33 pm

I would try to use Javascript injection to click those buttons.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Image Recognition Is Only Finding Image Sometimes...

Post by Dorian (MJT support) » Tue Apr 04, 2023 6:41 pm

rjw524 wrote:
Tue Apr 04, 2023 6:27 pm
Dorian (MJT support) wrote:
Tue Apr 04, 2023 6:10 pm
It's odd that it found them before, but isn't now. Ordinarily that would suggest the images have changed very slightly (particularly as you're using EXACT) and the advice would be to re-sample the images - but you've already done that.

If RedFound is always 0, try experimenting with increasing the tolerance from 0.7. You can find an explanation of that here.

This is of course if you're 100% sure the images are at the correct position you have specified in ScreenCapture, and if those images are actually visible.

You could also try looking for the images in a specified window instead of a screen area.
So let me ask...I thought I could only increase the tolerance with CCOEFF? That works for EXACT as well? Because the script has to click on image in the array.

Thanks!

rjw524
That is covered in the help file I linked to.
Yes, we have a Custom Scripting Service. Message me or go here

rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Re: Image Recognition Is Only Finding Image Sometimes...

Post by rjw524 » Tue Apr 04, 2023 8:19 pm

Grovkillen wrote:
Tue Apr 04, 2023 6:33 pm
I would try to use Javascript injection to click those buttons.
I would LOVE to do that but I don't know the first thing about Javascript lol!

rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Re: Image Recognition Is Only Finding Image Sometimes...

Post by rjw524 » Tue Apr 04, 2023 8:21 pm

Dorian (MJT support) wrote:
Tue Apr 04, 2023 6:41 pm
That is covered in the help file I linked to.
That NAILED it! Thanks a lot!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1378
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Image Recognition Is Only Finding Image Sometimes...

Post by Dorian (MJT support) » Tue Apr 04, 2023 8:24 pm

rjw524 wrote:
Tue Apr 04, 2023 8:21 pm
Dorian (MJT support) wrote:
Tue Apr 04, 2023 6:41 pm
That is covered in the help file I linked to.
That NAILED it! Thanks a lot!
Excellent!
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts