Forum Discussion

jpolvino's avatar
jpolvino
Occasional Contributor
3 years ago

Struggling with handing an object if it exists, and ignoring it if it doesn't

I have a web page (non-mobile) that I'm trying to test, and it sometimes has a button that needs to be pressed. I'd like to have python code that works like "if the button exists, press it, otherwise...
  • Kitt's avatar
    3 years ago

    You definitely need to use a WaitNNN method, but I think you need to try WaitNamedChild or WaitAliasChild since you are using name mapping.

     

    You cannot use mapped names with WaitElement bc the object selector needs to be an XPath expression or a CSS selector. And the Find method cannot find an object that does not exists, so you'll have to use a Wait method in combination with the Exists property. Try:

     

    def WaitAliasChildExample():
      # Specifies the Alias object
      AliasObj = Aliases.browser.pageName.formAspnetform
      # Checks whether the submit button has appeared within 10 seconds
      if (AliasObj.WaitAliasChild("submitbuttonDelete", 10000).Exists): 
        Log.Message("The submit button exists")
      else:
        Log.Error("The submit button does not exist")

     

    [TestComplete reference].