The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

Pages: 1
Learning2QTP
Member


Reged: 12/31/08
Posts: 295
How to select random object from drop down list
      #601192 - 11/12/09 01:34 PM

Hey all,

Im having some problems with one of my scripts and Im hoping you guys can help me figure out the issue.

Basically - I have a bunch of drop down boxes that Im pulling data from - I can easily record using QTP and it'll automatically select this from my drop down. However, Im not having any luck to select one RANDOMLY from the drop down box... I would like it - if the script will take a random value instead of having one hard coded via recording.

As a side section that I do have working - I wanted to grab a random link from the entire page (not the drop down) and as I said - this is working correctly - I thought posting it would be helpful in troubleshooting...

----------------------------------

Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Wait (10)

Set Links = Browser.Page.ChildObjects(oDesc)

'Get a total number of links so we know how many to process
NumberOfLinks = Links.Count()

Do Until svType > 0
Randomize nActiveLink = Int((NumberOfLinks * Rnd) + 1)
' Generate random value between 1 and NumberOfLinks

Wait(1)

'Get the outerHTML value
svOuterHTML = Links(nActiveLink).GetROProperty("outerHTML")

svType = InStr(svOuterHTML, "product/")
'product is being parsed from the URL - this is what Im grabbing

Loop

Links(nActiveLink).Click

----------------------------------

This code is working - I left my comments in so you can see what Im trying to do. What I want to do is before the svType to grab a random value from a drop down, THEN finish my loop above to pick a link from that page... The drop down is using a sort feature - so by adding this in I can REALLY select a random link not just a "random link on one page".

If I record with QTP - I get the following:
Browser.Page.WebList("type").Select "Item-in-list" - which obviously works but will always select the hard coded value.

Is there any fairly simple way I can select a random value here?

Any insight would be appreciated - hopefully I provided enough info without creating a huge wall of text

Cheers!


Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: How to select random object from drop down list [Re: Learning2QTP]
      #601199 - 11/12/09 02:45 PM

Hi,

This is quite a simple approach to select a random value from a listbox:


Dim intItemsCount

intItemsCount = Browser("").Page("").WebList("").GetROProperty("items count")

Browser("").Page("").WebList("").Select "#" & RandomNumber.Value(0, intItemsCount - 1)

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
Learning2QTP
Member


Reged: 12/31/08
Posts: 295
Re: How to select random object from drop down list [Re: AnshooArora]
      #601203 - 11/12/09 02:57 PM

Quote:

Hi,

This is quite a simple approach to select a random value from a listbox:


Dim intItemsCount

intItemsCount = Browser("").Page("").WebList("").GetROProperty("items count")

Browser("").Page("").WebList("").Select "#" & RandomNumber.Value(0, intItemsCount - 1)




Nice dude - that really helps me go in the right direction. I need to tweak it a little due to my script needing a bunch of these values but this really puts me in the right direction (and I at least have it working on one drop down box now) Hopefully I can use the same variable for multiple drop downs but if not - It should be much easier to do them separate with your help/code listed.

Very much appreciate the reply... Cheers!


Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: How to select random object from drop down list [Re: Learning2QTP]
      #601215 - 11/12/09 05:47 PM

Quote:

Hopefully I can use the same variable for multiple drop downs but if not - It should be much easier to do them separate with your help/code listed.




You can also use the following function for your requirement if you need to repeat this operation multiple times:


Function SelectRandom(oList)
oLink.Select "#" & RandomNumber.Value(0, oList.GetROProperty("all items") - 1)
End Function
RegisterUserFunc "WebList", "SelectRandom", "SelectRandom"

Usage:

Browser("").Page("").WebList("").SelectRandom

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 56 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 2830

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5