Micro Focus QTP (UFT) Forums
Select Menu items - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Select Menu items (/Thread-Select-Menu-items)



Select Menu items - shilpaS - 06-18-2015

Hello,

I have a web based application in which there is a menu bar, and i have to select an item from it.

Ex: Testing--> SDLC
I need a method which will accept the object details and will select SDLC option or if i pass another item details under another menu, it should select that as well.
AND
Testing-->Automation Testing--> QTP.
I have to select "QTP" here. I tried recording the menu, but it wasnt recognised. I need a generic function in which I will be passing the "QTP" object hierarchy details. Also, If I pass another object details say "Selenium" (Testing-->Automation Testing--> Selenium) , it should select that as well.

Please help me!!!!! I am quite new to QTP.
We are using UFT 11.53


RE: Select Menu items - supputuri - 06-19-2015

Option 1:
You can use the xpath of the menu item and click on the item directly. Check the below snippet (used to click on the 'Support Matrix -> Windows Support Matrix" menu item.
Code:
Browser().Page().WebElement("xpath:=//ul[@id="primary"]//a[text()='Windows Support Matrix']").Click

Option 2:
You can use the mouse over on until you hit the last item and then click on the last menu item in the input. Below is the skeleton of code (did not got a chance to execute, so please modify the function as per need.)
Code:
Public Function SelectMenuItem(oPage,sMenuPath)
    'Make sure the path contains submenu items and path is mentioned correctly
    If instr(sMenuPath,"->")>0  Then
        aMenuItems = Split(sMenuPath,"->")
    End If
    'Loop through the menu items and click on the last item
    For iMenuItem = lbound(aMenuItems) to Ubound(aMenuItems)-1
        oPage.WebElement("xpath:=//a[text()='" & aMenuItems(iMenuItem) & "']").FireEvent "onmouseover"
    Next
    oPage.WebElement("xpath:=//a[text()='" & aMenuItems(ubound(aMenuItems)) & "']").Click
End Function

Let me know if you need any more help on this.