Micro Focus QTP (UFT) Forums
how to randomly Select any category link and randomly click on one of its options ? - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: how to randomly Select any category link and randomly click on one of its options ? (/Thread-how-to-randomly-Select-any-category-link-and-randomly-click-on-one-of-its-options)



how to randomly Select any category link and randomly click on one of its options ? - sharavan - 11-18-2014

I m a fresher in QTP and want to learn Dynamic Descriptive Programming. I took HDFC bank website as an example and working on it. I was stuck at one point and kindly need your help.

I took a scenario like this:
QTP has to click on any of the category links randomly, then a drop down menu expands and has to randomly again select one of the options in that and then again randomly select the links in it finally.

Example:
The following is an example scenario, but i need this randomly.
QTP clicks "Products" link -----> Cards -------->Credit cards

Here is the code I prepared. But couldn't go forward:

Code:
'randomly Select any category link and click on one of the options.
SystemUtil.CloseProcessByName "chrome.exe"
SystemUtil.Run "chrome","http://www.hdfcbank.com/"

Function sRandNum(iMax,iMin)
        'Create Random Number within the Range
    Randomize
    sRandNum = Int(((iMax - iMin) * Rnd) + iMin)
End Function

'It only selects products,making payments or ways to bank links only
slRandomNumber=sRandNum(3,1)

Set MyBrowser= Browser("title:=.*")
Set MyPage= MyBrowser.Page("title:=.*")

Set hLink=Description.Create()
hLink("class").value="mainlink"
hLink("html tag").value="A"
hLink("height").value ="20"
hLink("innertext").value =".*"
hLink("index").value =slRandomNumber

MyPage.Link(hLink).FireEvent "onmouseover"

MyPage.WebElement("class:=mainlink","height:=35","html tag:=SPAN","innertext:=.*").FireEvent "onmouseover"

MyPage.Link("html tag:=A","height:=16","innertext:=.*","Index:=.*").Click


Thanks in advance.