Forum Discussion

atulghumade's avatar
atulghumade
New Contributor
6 years ago
Solved

Use Image from Image repository using for Loop

Hello Team,

Scenario:

"ImageRepository" has few images:

      ImageSet:

                     Image_1

                     Image_2

                     Image_3

                     .

                     .

                     Image_n

 

  • I can simply make "If_else"  and make multiple nested if's and Can use the following Statement:

         ImageRepository.ImageSet.Image_1.ClickM()

 

But How can use "for loop" and call the image from Image repository?

Like,

for n in "456":

  ImageRepository.ImageSet.Image_n.ClickM()

 

  • Hi,

     

    You need to use eval() or evaluate() function, depending on the scripting language of your test project.

    Algorithm:

    -- create a string that represents full name of the image/object;

    -- execute eval() to resolve the string to the object;

    -- call required method of the object.

     

    Sample pseudocode:

    var index = 1;

    var strObjName = aqString.Format('ImageRepository.ImageSet.Image_%i', index);

    var oObj = evaluate(strObjName);

    oObj.ClickM();

     

  • AlexKaras's avatar
    AlexKaras
    6 years ago

    atulghumade wrote:
    AlexKaras I'm using Python script. I googled and tried to find evaluate() function in Python but it didn't help. What is evaluate() in Python Script?

    >> You need to use eval() or evaluate() function, depending on the scripting language of your test project.

    https://www.programiz.com/python-programming/methods/built-in/eval was the first topic returned by this query: https://www.google.com/search?q=python+eval

    ;)

     

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    You need to use eval() or evaluate() function, depending on the scripting language of your test project.

    Algorithm:

    -- create a string that represents full name of the image/object;

    -- execute eval() to resolve the string to the object;

    -- call required method of the object.

     

    Sample pseudocode:

    var index = 1;

    var strObjName = aqString.Format('ImageRepository.ImageSet.Image_%i', index);

    var oObj = evaluate(strObjName);

    oObj.ClickM();