none
How do I check for existence of a child of a selected Tree View node? RRS feed

  • Question

  • I have a script where part of it checks to see if a specific Workspace name exists in a TreeView object:

    Private Sub Open_Proj_WS(Project As Variant)

        Dim WorkspcName As String
        Dim Proj_Items As TItems, Workspc_Exists As Boolean
        'Dim Item, Found As Boolean

    'Check if Workspace for project exists.
    'If not, create New Workspace from G-Station
        WorkspcName = "WS_" & Project
        'Found = False
        DotNETForm("GStation_Main").Attach
        'DotNETTreeView("GStation_ProjectView").Attach
        DotNETTreeView("GStation_ProjectView").SelectItem "\Project: " & Project & "\Workspaces"
        Workspc_Exists = DotNETTreeView("GStation_ProjectView").SelectItem("\Workspaces\" & WorkspcName, tpMouseLeft, tpTreeButton)

    It is the last statement where I get a "Control selection failed" run time error '-2147467259 (8004005)'.  My intention was to set the Workspc_Exists boolean variable to True if the WorkspcName item exists under the Workspaces node, and False if it doesn't.  At least that is what TestPartner supposedly told me should work as per the documentation.

    Please advise as to what methods, properties, and/or code changes are needed to make this block of code successful.  Thank you.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    Monday, June 18, 2012 10:48 PM

Answers

  • I did receive a solution from John Gilpin (a rep from Micro Focus, the manufacturer of the TestPartner automated testing tool I'm using).

    I replaced the following line of code (which generated the run-time error as a result of the SelectItem method):

    Workspc_Exists = DotNETTreeView("GStation_ProjectView").SelectItem("Workspaces\" & WorkspcName)

    With the following as per Mr. Gilpin's suggestion:

        If DotNETTreeView("GStation_ProjectView").TextExists(WorkspcName) = True Then
            Workspc_Exists = True
        Else
            Workspc_Exists = False
        End If

    Apparently, all I needed to do was perform the "TextExists" method to check for that specific workspace item.  Bottom line, use the "TextExists" method, and not the "SelectItem" method to find if a specific node item (parent or child) exists.  It's impossible to try selecting a non-existent item.

    Kudos to Mr. Gilpin at Micro Focus for providing me this solution.

    Thanks everyone.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    • Marked as answer by jbottiger2367 Tuesday, June 19, 2012 2:19 PM
    Tuesday, June 19, 2012 2:19 PM

All replies

  • I figured it out just now.  Apparently, I had an extra "\" in front of the second SelectItem parameter, which caused the "Control selection failed" Run-time error (i.e., a typo).

    Anyway, for those who want to check the existence of a specific item within a treeview node, the code looks like this:

    DotNETForm("GStation_Main").Attach
    DotNETTreeView("GStation_ProjectView").SelectItem "\Project: " & Project & "\Workspaces"
    Workspc_Exists = DotNETTreeView("GStation_ProjectView").SelectItem("Workspaces\" & WorkspcName)   'sets the result of the SelectItem method to a boolean variable

    If workspace item exists, then Workspc_Exists=True; else Workspc_Exists=False.

    Thanks for your help.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    • Marked as answer by jbottiger2367 Monday, June 18, 2012 11:23 PM
    • Unmarked as answer by jbottiger2367 Monday, June 18, 2012 11:27 PM
    Monday, June 18, 2012 11:22 PM
  • Actually, I stand corrected.

    When I tested this script with the WS_Test item non-existing, the Control selection failed run-time error came up again.

    Please feel free to offer any guidance that you may have.  Sorry to declare a victory too soon.

    Thanks.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    Monday, June 18, 2012 11:27 PM
  • I did receive a solution from John Gilpin (a rep from Micro Focus, the manufacturer of the TestPartner automated testing tool I'm using).

    I replaced the following line of code (which generated the run-time error as a result of the SelectItem method):

    Workspc_Exists = DotNETTreeView("GStation_ProjectView").SelectItem("Workspaces\" & WorkspcName)

    With the following as per Mr. Gilpin's suggestion:

        If DotNETTreeView("GStation_ProjectView").TextExists(WorkspcName) = True Then
            Workspc_Exists = True
        Else
            Workspc_Exists = False
        End If

    Apparently, all I needed to do was perform the "TextExists" method to check for that specific workspace item.  Bottom line, use the "TextExists" method, and not the "SelectItem" method to find if a specific node item (parent or child) exists.  It's impossible to try selecting a non-existent item.

    Kudos to Mr. Gilpin at Micro Focus for providing me this solution.

    Thanks everyone.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    • Marked as answer by jbottiger2367 Tuesday, June 19, 2012 2:19 PM
    Tuesday, June 19, 2012 2:19 PM