Forum Discussion

googleid_118035's avatar
googleid_118035
Contributor
11 years ago

Issue with getting an image of the selected object

Hi All,



I am try to get a calender popup window image through an JScripts.



Following are my approachs, but first approach only works?




function First_Approach()


{


var FilePath = "C:\\Dev_Chaminda\\Q2Soft\\TC003.jpg"


var myobject1 = Sys.Browser("iexplore").Page("http://localhost/Test/frmMyPage.aspx").Panel(0).Panel("cphMainContent_txtDOB_calendar_wrapper").Table("cphMainContent_txtDOB_calendar").Cell(1, 0).Picture();


myobject1.SaveToFile(FilePath);


}



 


function Second_Approach(){


var FilePath = "C:\\Dev_Chaminda\\Q2Soft\\TC003.jpg"


objectprop1 = new Array("ObjectIdentifier","ObjectType","Name","className");


objectvalue1 = new Array("1","Cell","Cell(1, 0)","rcMain");


 


var my_object1 = Sys.Browser("iexplore").Page("*").Find(objectprop1,objectvalue1, 2000, true).Picture();


my_object1.SaveToFile(FilePath);


}

  • Hi Dev,

     


    The Picture method doesn't seem to work as expected. I failed to reproduce this behavior on TestComplete 10.30. Most probably, it is reproduced only on TestComplete 10.0 that you are using. Can you upgrade to the latest product version?


     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    And what are the problems with the second approach?

    BTW, it might help if you also let us know the version of TC you are using...
  • Hi,



    In second appraoch scripts is running without an issue, but image not been created at given folder locations.



    Testcomlete version is;  10.0.531.7.





    ----------------------

    Thanks

    Dev
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Dev,

     


    TestComplete may not find the object based on the specified properties. Try debugging the code or modify it in the following way:




    function Second_Approach(){


      var FilePath = "C:\\Dev_Chaminda\\Q2Soft\\TC003.jpg"


      objectprop1 = new Array("ObjectIdentifier","ObjectType","Name","className");


      objectvalue1 = new Array("1","Cell","Cell(1, 0)","rcMain");


     


      var my_object1 = Sys.Browser("iexplore").Page("*").Find(objectprop1,objectvalue1, 2000, true);


      if (my_object1.Exists)


         my_object1.Picture().SaveToFile(FilePath);


      else


        Log.Message("The object wasn't found");


    }



  • Hi Tanya,



    Try with following code, but I return as "The object found".

    Code as below.


    function Second_Approach(){


      var FilePath = "C:\\Dev_Chaminda\\Q2Soft\\TC003.jpg"


      objectprop1 = new Array("ObjectIdentifier","ObjectType","Name","className");


      objectvalue1 = new Array("1","Cell","Cell(1, 0)","rcMain");


      var my_object1 = Sys.Browser("iexplore").Page("*").Find(objectprop1,objectvalue1, 2000, true);


      if (my_object1.Exists){


          my_object1.Picture().SaveToFile(FilePath);


          Log.Message("The object found"); 


         }


      else{


         Log.Message("The object wasn't found");


     }


    }





    ....................

    Thanks

    Dev

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Dev,



    Just a guess: does the C:\\Dev_Chaminda\\Q2Soft\\ folder exist?

    From TC help: "If the FileName parameter corresponds to a non-existent folder, TestComplete will fail to save the image to the specified path as it does not create folders specified in the path. It creates only specified files (if necessary). To solve the problem, create the needed folder using the CreateFolder method and then save the image to it using the Picture.SaveToFile method."
  • Hi Alexei,



    I am using the same folder structer in both appraoch, but only in second approah, that image not get created in the given folder location. 

    So folder is exsist.





    .........................

    Thanks

    Dev



  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi,

     


    Let's separate the execution of the Picture and SaveToFile methods to troubleshoot this. Execute this code and let us know what you see in the Test Log:






    function Second_Approach(){


        var FilePath = "C:\\Dev_Chaminda\\Q2Soft\\TC003.jpg"


        objectprop1 = new Array("ObjectIdentifier","ObjectType","Name","className");


        objectvalue1 = new Array("1","Cell","Cell(1, 0)","rcMain");


        var my_object1 = Sys.Browser("iexplore").Page("*").Find(objectprop1,objectvalue1, 2000, true);


        if (my_object1.Exists){


            Log.Message("The object found");       


            Log.Picture(my_object1.Picture());


            if (my_object1.Picture().SaveToFile(FilePath))


                Log.Message("The picture was saved");


        }


     else{


        Log.Message("The object wasn't found");


    }


    }







  • Hi Tanya,



    Thanks for the reply.

    Please find the execution results from the attach screenshot.

    according to that , the issue is with the picture method , I think. 





    .......................

    Dev

    Thanks
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Dev,

     


    The Picture method doesn't seem to work as expected. I failed to reproduce this behavior on TestComplete 10.30. Most probably, it is reproduced only on TestComplete 10.0 that you are using. Can you upgrade to the latest product version?


     

  • Hi Tanya,



    Thanks for the reply. I will discuess with management team to upgrade the TC.





    ...............

    Thanks

    Dev