Forum Discussion

joel_johnson's avatar
joel_johnson
Occasional Contributor
10 years ago

Click on picture instead of object

I have seen automated testing applications that find a certain "picture" on the screen and click on it, rather than finding an object and clicking on it.  The picture may just be of one letter on a button. Does TestComplete support this?  Some object recognition issues are hard to resolve.

  • NisHera's avatar
    NisHera
    Valued Contributor

    below is a fucntion I'm using in similer situations, written in JSscript

    Please modify according to your situation

     

    function clickPic(){
    var StordedPic, WinPicObj, YourWindow, RectHandle;
    StordedPic =Utils.Picture;
    StordedPic.LoadFromFile("C:\\.....\\MyButton.PNG");
    Log.Picture(StordedPic);
    YourWindow = Aliases.Application.....ParentObject //this is an object which Object Spy could read
    WinPicObj = YourWindow.Picture(0,0,-1,-1,false);
    Log.Picture(WinPicObj);
    RectHandle = WinPicObj.Find(StordedPic,0,0,false,Z,false,100); //Z should replace with a value =>0
    Log.Message(RectHandle.Top+" "+RectHandle.Left+" "+RectHandle.Bottom+" "+RectHandle.Right);
    YourWindow.Click(RectHandle.Left+5,RectHandle.Top+5,0);
    }