cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to find button object

Occasional Contributor

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;
}
}

5 REPLIES 5
Community Hero

Re: Unable to find button object

Community Hero

Re: Unable to find button object

Hi,

 

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

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Community Leader

Re: Unable to find button object

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.

Community Leader

Re: Unable to find button object

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


--------------------
QA Systems Architect
Integrated Control Technology
https://www.ict.co/
Community Manager

Re: Unable to find button object

thanks everybody for such great support!

 

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

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors