Search code examples
hp-uft

SAPGuiTree : TreeView Activate item issue


I am working SAPGuiTree and wants to activate item by passing value through parameter. if anyone knows about this kindly help me and here is my code

Code:

SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree","index:=0").ActivateItem "Inbound Monitor;03.05.2016;9395;Sales Movement","Sales Movement"

here bold leters are the data insteadof hardcoding i want to give input from datasheet.

DATE= 03.05.2016 date = parameter("DATE")

here is the code which i used parameter insteadof data but i am getting an error "Cannot identify the required object"

SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree","index:=0").ActivateItem "Inbound Monitor;date;9395;Sales Movement","Sales Movement"


Solution

  • So, you're using .ActivateItem method, which takes two parameters: Path, and Item. Path needs to be a string that contains items separated by semicolons, and Item is a string containing the text of the SAP item you want to activate.

    The error you're getting is probably caused by the fact that your Path parameter is failing to match an item in the control SAPGuiTree("treetype:=SapColumnTree","index:=0"). But, I think it's clear that you already understand that. You don't seem to understand how to build the string that Path needs to be, so let's work on that.

    I'm assuming that "Inbound Monitor;03.05.2016;9395;Sales Movement" worked. So, you need to build that up from a Datasheet. Since it's a string, we build it using concatenation. In VBScript used by QTP, that's done with the & operator.

    OK, let's build up the concepts.

    You have a datasheet with a column called DATE, and a record with a field value of "03.05.2016"

    'set a variable called date to the value of the datatable field "DATE" mentioned above
    date = DataTable("DATE")
    
    'concatenate strings together into a variable called Path
    Path = "Inbound Monitor;" & date & ";9395;Sales Movement"
    
    'the other parameter
    Item = "Sales Movement"
    
    SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree","index:=0").ActivateItem Path, Item
    

    This should work. However... I try NOT to use variables in QTP as much as possible, so...

    SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree","index:=0").ActivateItem "Inbound Monitor;" & DataTable("DATE") & ";9395;Sales Movement", "Sales Movement"