How can I verify if an object exists in VB.NET and then write the results to the TrueLog Explorer before continuing with the script execution?

How can I verify if an object exists in VB.NET and then write the results to the TrueLog Explorer before continuing with the script execution?

The VB.NET code below executed from Silk4NET demonstrates how to check if an object (located in an Object Map) exists or not, before writing the result to the TrueLog Explorer without ending the test regardless if the object exists or not. 

<TestMethod()> Public Sub TestMethod1()
           With _desktop.BrowserApplication("demo_borland_com")
                With .BrowserWindow("BrowserWindow")
                         Try
                            If DomButton.Exists("bSubmit") Then
                                 Agent.LogInfo("Sumbit Button Exists")
                            Else
                                 Agent.LogInfo("Submit Button Does not exist")
                            End If
                         Catch ex As Exception
                        End Try 

                        End With
                    End With
                End Sub
End Class

The VB.NET code below demonstrates the same functionality only in this instance we check if the object exists using the full “X-Path” locator string instead of an Object Map.

<TestMethod()> Public Sub TestMethod1()
               With _desktop.BrowserApplication("/BrowserApplication")
                  With .BrowserWindow("//BrowserWindow")        
                         Try
                            If .Exists(“//INPUT[@names=’bSubmit’]”) Then
                               Agent.LogInfo("Sumbit Button Exists")
                            Else
                               Agent.LogInfo("Submit Button Does not exist")
                            End If
                         Catch ex As Exception
                        End Try

                        End With
                    End With
                End Sub
End Class

The method “LogInfo()” will write the result to the object map.

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-09-19 10:11
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.