Forum Discussion

harshad_w's avatar
harshad_w
Occasional Contributor
4 years ago

Unable to find button object

Hi,

I have to click the Yes button in order to load the application completely. The attached pop-up window appears when I open a file using TestComplete. The pop-up window appears after some time when the product is launched. Here is the code I have written to click the Yes button. I am trying to wait for that button until it appears on the screen. First, I used the Find method, and then I used FindChildEx. The code is working intermittently. It's not able to find the button always. Can you please tell me what I need to change or is there a simple way to click the button as soon as it appears?

 

//Using the Find method

var counter = 0;
p = NameMapping.Sys.Process("ORD");

while(true)
{
Delay(3000);
if(counter > 100)
{
throw new error("Compact database did not appear")
}

var btnYes = p.Find("WndCaption", "&Yes", 500);

if(btnYes.Exists)
{
btnYes.Click();
break;
}
counter++;

}

 

//Using the FindChildEx method

 

Delay(5000)
p = Sys.Process("ORD")
if(p.Exists)
{
var yesBtn = p.FindChildEx("WndCaption", "&Yes", 10, true, 1000);
var counter = 1;
while(!yesBtn.Exists)
{
Delay(2000);
yesBtn = p.FindChildEx("WndCaption", "&Yes", 10, true, 1000);
counter++;
if(counter > 50)
{
break;
}
if(yesBtn.Exists)
{
yesBtn.ClickButton();
break;
}
}

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I would first wait for the 'Compact Database' dialog and then look for its child 'OK' button.

     

    • anupamchampati's avatar
      anupamchampati
      Frequent Contributor

      Try with Wait Window code
      var p = NameMapping.Sys.WaitProcess("ORD",5000) ///you can increase the wait delay in milli seconds
      if (p.Exists)
      {
      var btnYes = p.Window("Button", "&Yes", 7);
      btnYes.Click();
      }
      else
      {
      Log.Error("Compact database did not appear");
      }

      if the above does not work than may be your objects are dynamically changing, try to find the changing index in object and try to use Find for the same.

      • tphillips's avatar
        tphillips
        Frequent Contributor

        I always make extensive uses of waitAliasChild in my testing, it's made our testing so much more robust.

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    thanks everybody for such great support!

     

    harshad_w, was the issue resolved? Please share with us the solution you decided to use.