Forum Discussion

nb_autoTester's avatar
nb_autoTester
Occasional Contributor
9 years ago
Solved

Need a clever way to determine if an object is still visible on the screen

During my automation, I have a small popup that I have to select some radio buttons on and then an OK button that I need to click, but occasionally when I click it the click does not register, so I need to click again to close the popup.

 

I'm getting the object by:

 

  Set btn_Detail_Ok = page.FindChildByXPath("//a[@name='Ok']", True)

My first attempt was to just check if it Exists after we click it once:

  'Get the Ok button on the Level of Detail Options popup
  Set btn_Detail_Ok = page.FindChildByXPath("//a[@name='Ok']", True)
  btn_Detail_Ok.Click
  Log.Message("Clicked Ok button")
  aqUtils.Delay(2000)
  
  'If the Ok button still exists, click it again
  If btn_Detail_Ok.Exists Then
    btn_Detail_Ok.Click
    Log.Message("Clicked Ok button again")
  End If

But this does not work because the OK button exists all the time. To test this, I added this line of code before the small popup appears:

 

  Set btn_Detail_Ok_Dup = page.FindChildByXPath("//a[@name='Ok']", True)

And sure enough, I get the correct object.

 

I've looked at all of the properties of the object (visible, enabled, disabled, visibleOnScreen) and they're all the same. I'm looking for another way I can determine if we need to click the button again. Any ideas are appreciated.

  • try multiple attributes and value in xpath like - Class/type, value, id, name etc., which is unique identifier for your object.

     

    Sample xpath for button - ("//input[@name='ok'][@type='button'][@id = 'sub1']")

     

     

4 Replies

  • Manfred_F's avatar
    Manfred_F
    Regular Contributor

    the "visible" property should help, it did it for me at least.

     

    First, check "exists". Then check "visible", but: be careful: while checking "visible", the object may stop its existence and You get an error, so use error handling here.

    • nb_autoTester's avatar
      nb_autoTester
      Occasional Contributor

      Manfred_F I checked every property of the button before the popup is displayed and after the button is displayed. Every single property is the same, there are no differences. What I did was create a button1 and Set that before the popup is displayed, and a button2 and set that after the popup is displayed. Each object had the exact same properties. 

       

      Ravik Thanks for the suggestion, it worked! After I click the button once, I try to get the button again:

       

       

      Set btn_Detail_Ok = page.FindChildByXPath("//*[@id='levelOfDetailDialog_ACTION_1'][@name='Ok'][@tabindex='2002']", True)

      Then, if btn_Detail_Ok is still there, click it again.

       

        'If the Ok button still exists, click it again
        If Not btn_Detail_Ok Is Nothing Then
          btn_Detail_Ok.Click
          Log.Message("Clicked Ok button again")
        End If

       

  • Ravik's avatar
    Ravik
    Super Contributor

    try multiple attributes and value in xpath like - Class/type, value, id, name etc., which is unique identifier for your object.

     

    Sample xpath for button - ("//input[@name='ok'][@type='button'][@id = 'sub1']")

     

     

  • chrisb's avatar
    chrisb
    Regular Contributor

    Exists isnt a good check of whether the object is visible. The object may well exist and not be visible to user. Exists just means the object is in Test Completes object tree. Try the VisibleOnScreen property and write logic to use the true / false value of this property to determine if the object is displayed to user.

    FYI, Visible is not a true indicator as to whether user can see the object. If VisibleOnScreen gives false positives then perhaps you can check the dimensions of the object (height / width), they should indicate when the object is not visible to user. I think VisibleOnScreen will work for you though if you check the value of that property and use it to determine if the object is displayed to user.