Forum Discussion

tetzura's avatar
tetzura
New Contributor
2 years ago

If Else condition is failed anyway

Keyword test is failing in any case when I'm using If else condition, this is the example:

 

So what's happening: if condition 1 in IF stat == true - then Test is green and passed.

when IF condition FALSE, then test goes to Else condition, do Else condition, BUT the test is red and failed because it cant find the object from first IF condition. 

Isn't there a way to work as OR statement or SKIP the first condition if its false and not show the results as failed (even if else condition is done)???

"If (Aliases.browser.pageMyTestProject.FindElement("xpath to existed order").Exists == true){
Aliases.browser.pageMyTestProject.FindElement("xpath to existed order").Click();}
else { Aliases.browser.pageMyTestProject.FindElement("xpath to create New button ").Click(); }"
  • Kitt's avatar
    Kitt
    Regular Contributor

    You need to use a Wait method, like WaitElement() instead of FindElement() - see remarks [here] and below:

     

    If TestComplete fails to find the object whose Exists property you are checking, an error will occur. For example, the code below will fail if the process TestedApp does not exist in the system: 

     

    // If the process does not exist, an error will occur
    if (! Sys.Process("TestedApp").Exists ) 
      …

     

    Do not use Exists this way. Use the WaitNNN methods to get the needed object first. If the requested object does not exist, this method will return a stub object whose Exists property will be False.