Forum Discussion

mcaffrey's avatar
mcaffrey
New Contributor
6 years ago

TestComplete tries to find object that are not on screen.

I'm trying to write a module in python that opens menu items, and closes them in a .NET application. For some menu items, closing the window triggers an alert box. When I put the object into TestComplete it tries to find it even when it's not on screen causing my test to fail. Here's an example:

 

def MyTest():

  # Objects mapped in TestComplete, and a list of items to click

  mainPage = Sys.Process("MyApplication").WinFormsObject("MyApp")

  alertBox = Sys.Process("MyApplication").WinFormsObject("AlertBox")

  items = ['Item1', 'Item2', 'Item3', 'Item4']

 

  # Open each item, and close it with hotkey. If the alertbox is visible click 'Yes' to close. 

  for i in range(0, len(items)):

    mainPage.Click(items(i))

    mainPage.Keys("[Esc]")

    if alertBox.Visible:

      alertBox.Click("Yes")

 

I've tried setting the Alert Box to visible, onscreen, and exists. If it's not on the screen the test fails. Does anyone know how to get around this? My actual script involves close to a dozen menu items, and a few dozen sub-items so adding in the Alert box to each one is tedious along with making it difficult to maintain since the Alert Box can be in different menus. Anyone know a way how to get TestComplete to ignore an object if it's not onscreen?

 

I don't understand why it keeps trying to find it. Even if I only click items without the alert box it still fails since it keeps trying to find the object.