FindImagePos seems to fail under certain conditions

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Heinz57
Junior Coder
Posts: 28
Joined: Wed Jul 22, 2015 6:10 pm
Location: A Berliner just east of Wien

FindImagePos seems to fail under certain conditions

Post by Heinz57 » Wed Jul 29, 2015 6:50 am

Hello again,

Much of my first juvenile euphoria caused by MacroScheduler has been washed away by some unexplainable problems the most severe of which is the fact that FindImagePos seems to fail under the conditions specified here below.

First a word about the scenario:

a) There is our existing database application ("DBApp") where DB records are selected so that some of their content can be posted to a third party website.

b) There is an instance of IE11 created by MacroScheduler ("MSched" for short). It receives the url to load from DBApp currently via the clipboard (later SDK is planned) and subsequently it also receives some text to post inside the loaded browser.

Second, there are these buttons with graphics affected:

There are four buttons in IE delivered from the said website. MSched ALWAYS finds them perfectly through FindImagePos.

Within DBApp there are these four (currently very ugly) big action buttons and this is where the problems come up.

Image

The main logic in MSched loops through the records previously selected in DBApp. For every record the script performs these actions:
  • Press button 1 and then perform some IE actions
    Press button 2 and then perform some IE actions
    When they were fined properly, press button 3 in DBapp
    End of one loop cycle. Start all over again.
Here is the problem: The buttons in DBApp are only detected properly during the first loop cycle and never again thereafter. This is the case although absolutely the same code is used in subroutines and the state of the related variables is also identical.

I have spent yesterday about 12 hours on this problem, I checked the code multiple times and I cannot see any differences in the code or variables between the first and any subsequent loop cycle.

Code: Select all

// -------------------------------------------------------------------------------------
// Find DBApp Profile browser Button 1 and open new IE on profile
SRT>ESOFindProfileBrowserButton1
Let>resProfileSkip=NO
Gosub>PCRActivateWindowDBApp
//Find and Left Click Center of
FindImagePos>%SysVarDirBmp%\ESOPCRButton1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.5
  LClick
  Wait>1
  // get next URL from clipboard as inserted by DBApp
  GetClipBoard>currURL,0
  Gosub>IECreateNew,currURL
  Gosub>PCRSentCheckProfileMissing
ELSE
   Gosub>PCRMsgESONotFoundEndApp
Endif
END>ESOFindProfileBrowserButton1
// -------------------------------------------------------------------------------------
// Find DBApp browser Button 2 - get text to be sent in IE
SRT>ESOFindProfileBrowserButton2
Gosub>PCRActivateWindowDBApp
//Find and Left Click Center of DBApp button
FindImagePos>%SysVarDirBmp%\ESOPCRButton2.bmp,SCREEN,0.7,1,XArr,YArr,NumFound,CCOEFF
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  Wait>0.5
  LClick
  Gosub>IEWaitForIE
  // keep PCR text in currText till needed
  Wait>1
  WaitClipBoard
  GetClipBoard>currText,0
  Wait>1
ELSE
  Gosub>PCRMsgESONotFoundEndApp
Endif
END>ESOFindProfileBrowserButton2
I also changed the arguments in FindImagePos from searching the entire screen to some active window as in the code below but this made no change:

Code: Select all

FindImagePos>%SysVarDirBmp%\ESOPCRButton1.bmp,WINDOW:SysESOTitleProfileBrowser,0.7,1,XArr,YArr,NumFound,CCOEFF
Again: It works always in the first run but never thereafter. The same after being restarted. I have tried many "hacks" like saving the script under a new name, closing and restarting MSched and so forth but there was always the same result: ok during the first runs, no images found during the second run.

As for the moment I worked around this through a hack by storing absolute x/y coordinates during the first run but this still worries me because I am currently still in the testing phase and my intent is to base a whole new product on the use of MSched and to go through the SDK.

I should mention that the related DBApp window is not (what I would call) a native Windows window but it is a child window of the DBApp's main form (pardon, I am not a compiler user; after using pure o-o since 1986 I don't want to go back to the Flinstones, bother about mallocs, pointers and all this stuff).

What could be the reason of all of this? I could also send you the entire code and the bmp files if that helps.

Best regards
Heinz57

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: FindImagePos seems to fail under certain conditions

Post by Marcus Tettmar » Wed Jul 29, 2015 10:55 am

If the screen isn't changing but it fails second parse then there is most likely something in your script which is changing one of the values. What the app is made with doesn't matter because FindImagePos cares only about screen shots - it's purely visual. What is the value of NumFound? Anything silly like a variable called "1" being accidentally set to something other than 1? Feel free to send your script to support so we can check it out.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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