Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code check- Random number
#1
Solved: 11 Years, 4 Months ago
Hi All,

Please have a look at my code given below:

Code:
1. For i = 1 to 3
2. Mrkt = Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Market").GetTOProperty("items count")
[color=#32CD32]'trying to get number of items in the Market list.[/color]
    wait(5)
3. Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Market").Select RandomNumber(1, Mrkt )
[color]'Selecting a random number for the list Market in the range 1 to Mrkt (variable defined in the earlier set)[/color]
    wait(5)
4. loctn = Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Location").GetTOProperty("items count")
[color]'trying to get number of items in the Location list[/color]
    wait(7)
5. Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Location").Select RandomNumber(1,loctn)
[color]Selecting a random number for the list Market in the range 1 to loctn (variable defined in the earlier set)[/color]

Next
My doubt: Is there a mistake in the code ? Can I pass a variable as the range in RandomNumber??? When I run this script lines 3 and 5 always select '1' item in the list and I see line 5 fails at times showing - object was not found.

Please help me where have I gone wrong ????

Thanks
Swetha
Reply
#2
Solved: 11 Years, 4 Months ago
Hi Swetha,
Yes you can pass the variable as a range for RandomNumber

you have used 'GetTOProperty'. there is no any method as such in QTP a similar method is GetTOProperties return properties and values of an object used to identify the object. you should use GetROProperty to retreive the value of a particular property.

when you use 'select' for a weblist, if you are using the item in the list you can put the item derectly to select but if you use index then you should use "#1","#2" etc.

I have tried to modify your code
Code:
For i = 1 to 3
Mrkt = Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Market").GetROProperty("items count")
'trying to get number of items in the Market list.
wait(5)
Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Market").Select "#" & RandomNumber(1, Mrkt )
'Selecting a random number for the list Market in the range 1 to Mrkt (variable defined in the earlier set)
wait(5)
loctn = Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Location").GetROProperty("items count")
'trying to get number of items in the Location list
wait(7)
Browser("TalonPro Solutions").Page("TalonPro Solutions").WebList("Location").Select "#" & RandomNumber(1,loctn)
'Selecting a random number for the list Market in the range 1 to loctn (variable defined in the earlier set)
Next

let me know if this helps

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a random number starting with an alphabet QTPmate 4 4,193 07-31-2014, 09:29 AM
Last Post: QTPmate
  Random Values from Drop-Down profqa 5 6,025 12-06-2013, 09:01 AM
Last Post: basanth27
  Creating Random String SomeIntern 0 5,082 08-21-2013, 09:10 PM
Last Post: SomeIntern
  Can some one check my code and tell me whats wrong in it. zakshah.12 3 3,875 03-06-2013, 03:26 AM
Last Post: newqtp
  Random Number generator and verification problem jinnah 4 10,415 09-28-2012, 04:03 AM
Last Post: jinnah

Forum Jump:


Users browsing this thread: 1 Guest(s)