Forum Discussion

joffre's avatar
joffre
Regular Contributor
13 years ago

TestComplete script - What am I doing wrong?

What am I doing wrong on the code below?


function findAndClick_BtnAssociacao()



{



var BtnAssociacao = Sys.Browser().Page("*").Panel("tabs").Panel("tabs_1").Panel(0).Panel(1).Panel(0).Panel("panelInicial").Find(Array("contentText"), Array("Associação"), 1000);



// find a button and see if it is enabled



if (BtnAssociacao.Exists && BtnAssociacao.Enabled) {



// if found



// click on it



BtnAssociacao.Click();



// find a panel that is shown just if the button BtnAssociacao is found



var PnlTitle = Sys.Browser().Page("*").Panel("tabs").Panel("tabs_1").Panel(0).Find(Array("ObjectType", "idStr", "contentText"), Array("Panel", "title", "Associação"), 1000);



// while the panel doesn't exist, i'll perform a click on BtnAssociacao



while (!PnlTitle.Exists) {



BtnAssociacao.Click();



}



// If not found or not enabled, error log generated



} else {



Log.Error("The attempt to click on the specified menu have failed.");



}



}


5 Replies

  • sastowe's avatar
    sastowe
    Super Contributor
    Where is the undesired behavior? I see this



    if (BtnAssociacao.Exists && BtnAssociacao.Enabled)



    gives me pause. I don't remember for sure. But I think the scripting engine needs to be able to evaluate the whole conditon.



    So let's say
    BtnAssociacao.Exists is false. The && BtnAssociacao.Enabled will still be evaluated. Which it cannot if it does not exist.



    Just a thought.


  • joffre's avatar
    joffre
    Regular Contributor
    The problem is that the PnlTitle is been found, the BtnAssocial is been clicked, but my script doesn't leave the loop.



    Don't know why.



    The problem is on this fragment:




    while (!PnlTitle.Exists) {

     BtnAssociacao.Click();

    }




    The BtnAssociacao is clicked, the PnlTitle is found, but it doesn't end. Ever!



    Hope you can help me.



    Thanks!
  • joffre's avatar
    joffre
    Regular Contributor


    Hi Paul, thanks for your answer!



    I've already did that, but on that case, the problem is other. Instead off entering a loop and click several times, it doesn't recognize the PnlTitle and doesn't click at all.



    Thanks for your support.


  • Hi Joffre,



    I think the problem is that you are checking that the object exists, but you are not searching again for it again, so it will never exist.



    You can try something like that:



    // Search for the object and assign it to PnlTitle



    while ( !PnlTitle.Exists ) {

      // Search for the object and assign it to PnlTitle

      // Click on button

    }



    You could also add a counter to the while, so it won't enter an infinite loop.



    Hope it helped!