Forum Discussion

Mark1's avatar
Mark1
Contributor
6 years ago

If statement for VisibleOnScreen is failing when object is not on screen

I have a method where if the a specific dialog box is VisibleOnScreen it will click the ok button and carry on else it just carries on as normal. This dialog box is just a warning that the software being tested was closed incorrectly last time it was used. It not guaranteed to show up every time you run a test but it will only ever appear at this one specific time I run this method.

The issue occurs when the dialog box does not appear but since I have a variable which is set to that dialog box, if gives an error since it couldnt get the dialog box and carries on with the rest of the test. How do I get around this issue. Here is an example of what I mean.

 

Sub OKClick

Set DialogBox = Sys.Process("softwareBeingTested")....etc

If DialogBox.VisibleOnScreen Then

'click ok button

Else Log.Message "No dialog box appeared 

End If

End Sub

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Your "Set" call... are you using anything like a WaitChild or FindChild or anything to find the Dialog box?  The reason I ask is that you cannot call the "VisibleOnScreen" property of an object that does not exist.  Your Set call, if the dialog isn't actually extant in memory of your application, will return a Null value which HAS no properties.  You should always check for "Exists" before you attempt to interact.

    • Mark1's avatar
      Mark1
      Contributor

      No, what I have in my example is exactly what I have in my method. So would the following work

       

      Set U=Sys.Process("softwareName").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).WaitChild("softwareName",2000)
      If U.VisibleOnScreen Then
      Sys.Process("softwareName").WPFObject("HwndSource: PopupRoot", "").WPFObject("PopupRoot", "", 1).WPFObject("Decorator", "", 1).WPFObject("NonLogicalAdornerDecorator", "", 1).WPFObject("Grid", "", 1).WPFObject("messagecontent").WPFObject("grid1").WPFObject("Border", "", 1).WPFObject("StackPanel", "", 1).WPFObject("StackPanel", "", 1).WPFObject("left").Click()
      Log.Message" Button was clicked"
      Else Log.Message" Button was not clicked"
      End If

      • m_essaid's avatar
        m_essaid
        Valued Contributor

        Hi,

        Robert just said what you need, even you check the "exists" then the "visible" in a nested condition, even you use wait methods that accepts to wait for objects that may not exist.