Created On:  26 October 2011


Using a 'Try...Catch' statement will deal with the errors flagged by the WaitforObject method. Silktest Workbench is working as-designed for the WaitforObject method with flagging an exception if the timeout is reached.
The catch method will allow the exception to be dealt with and move on with the script execution.

Below is an script example showing this working:

Imports
SilkTest.Ntf.XBrowser
Public Module Main
       Dim _desktop As Desktop = Agent.Desktop
 
       Public Sub Main()
              With _desktop.BrowserApplication("WebBrowser")
                                  With .BrowserWindow("BrowserWindow")
                                         .DomTextField("lst-ib").TypeKeys("test")
                                         .DomButton("btnG").Click()
                           Try
                                  .WaitforObject("//DIV[@sig='G-r']//H3/A", 5000)
                                  Console.WriteLine ("after missing object, this line is never reached")
                           'review details about class system.exception in msdn
                           Catch e As Exception
                                  Console.WriteLine("Exception: {0}", e.ToString())
                           End Try
                           .DomElement("News").Click()
                           Console.WriteLine ("to News link")
                     End With
                     .SetActive()
                     .DropDownToolItem("Home").Select()
                     Console.WriteLine ("to Home page")
              End With
       End Sub
End Module
 
In this example, I have Internet Explorer set as an application configuration to start in the google page: http://www.google.co.uk/webhp?hl=en
For the above code to work for you, the object maps must exist.
 
Explanation:
After the application state is set, I then type test into the search field and click the search button. Then, I wait for an object that doesn't exist and finally output a detailed message with the string representation of the current exception, then playback resumes next with a click in the news link in the google page and finally I then go the browser home page.
 
Here is an example of the actual console output:
.NET Script 'TryCatchError' Started
Exception: SilkTest.Ntf.ObjectNotFoundException: Could not find object '//DIV[@sig='G-r']//H3/A'.
   at SilkTest.Ntf.Communicator.SendMessage(Message message)
   at SilkTest.Ntf.Agent.SendMessage(Message message)
   at SilkTest.Ntf.Agent.Invoke(TestObject invokeObject, String methodName, IList parameters)
   at SilkTest.Ntf.TestObject.Invoke(String methodName, Object[] parameters)
   at SilkTest.Ntf.TestObject.WaitForObject(String locator, Int32 timeout)
   at Main.Main() in C:\Users\mfuseto News link
to Home page
.NET Script 'TryCatchError' Completed
 
With Visual Testing you can use error handler to surpress issues.