Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frustrated with Random Numbers - Help :(
#1
Solved: 10 Years, 9 Months, 1 Week ago
Hi,

Am quite new to this QTP and am just wondering how can I generate random numbers and let QTP click on that random number that got generated?

Someone before me used the following to generate the random numbers:
Code:
Dim uniqueNumber
Randomize
uniqueNumber=Int((1000000)*Rnd)


and then he used the following:
Code:
row=Browser("ad1Domain").Page("ad1Domain_2").WebTable("EntryNewsletterRegistrationAdmin").GetRowWithCellText(CStr(uniqueNumber))
Browser("ad1Domain_2").Page("ad1Domain").Link("DELETE").SetTOProperty "index",row-2
Browser("ad1Domain_2").Page("ad1Domain").Link("DELETE_2").Click


My problem is that the link in my case is randomly generated number. How can I tell Mr. QTP to find the random number generated and click it? Aaaah, this is killing me...
Reply
#2
Solved: 10 Years, 9 Months, 1 Week ago
If no one understand how that is working then can someone tell me how to generate random numbers and tell QTP to click on that randomly generated number?

Does that make it easier or..? Smile
Reply
#3
Solved: 10 Years, 9 Months, 1 Week ago
I had that problem with random numbers some yeeks ago, I don't know if it's the same, but I think that this will help you.

This video bellow is what I used to uderstand how to do that.

http://motevich.blogspot.com/2008/08/qtp...-link.html

If you have some questions, fell free to ask Smile
Reply
#4
Solved: 10 Years, 9 Months, 1 Week ago
Hi ,
You can try if the below mentioned code works for you:

Code:
Dim bytes1(99), bytes2(99) As Byte
Dim rnd1 As New Random()
Dim rnd2 As New Random()

rnd1.NextBytes(bytes1)
rnd2.NextBytes(bytes2)

Console.WriteLine("First Series:")
For ctr As Integer = bytes1.GetLowerBound(0) to bytes1.GetUpperBound(0)
   Console.Write("{0, 5}", bytes1(ctr))
   If (ctr + 1) Mod 10 = 0 Then Console.WriteLine()
Next
Console.WriteLine()
Console.WriteLine("Second Series:")        
For ctr As Integer = bytes2.GetLowerBound(0) to bytes2.GetUpperBound(0)
   Console.Write("{0, 5}", bytes2(ctr))
   If (ctr + 1) Mod 10 = 0 Then Console.WriteLine()
Next  
' The example displays the following output to the console:
'       First Series:
'          97  129  149   54   22  208  120  105   68  177
'         113  214   30  172   74  218  116  230   89   18
'          12  112  130  105  116  180  190  200  187  120
'           7  198  233  158   58   51   50  170   98   23
'          21    1  113   74  146  245   34  255   96   24
'         232  255   23    9  167  240  255   44  194   98
'          18  175  173  204  169  171  236  127  114   23
'         167  202  132   65  253   11  254   56  214  127
'         145  191  104  163  143    7  174  224  247   73
'          52    6  231  255    5  101   83  165  160  231
'      
'       Second Series:
'          97  129  149   54   22  208  120  105   68  177
'         113  214   30  172   74  218  116  230   89   18
'          12  112  130  105  116  180  190  200  187  120
'           7  198  233  158   58   51   50  170   98   23
'          21    1  113   74  146  245   34  255   96   24
'         232  255   23    9  167  240  255   44  194   98
'          18  175  173  204  169  171  236  127  114   23
'         167  202  132   65  253   11  254   56  214  127
'         145  191  104  163  143    7  174  224  247   73
'          52    6  231  255    5  101   83  165  160  231

-Rachna
Reply
#5
Solved: 10 Years, 9 Months, 1 Week ago
Hi Scanditester, I received your email. I'll try to explain that for you.

If you watched the link that I put in my other post it will help you, anyway, I think that you need to do the following:

*Save your script on QTP.
*When you came to desired screen you can view it on QTP on "Active Screen" tab (View -> Active Screen).
*There I think that you will see that random ID, highlight that and click with the right button on it and select the "Insert Text Output" option.
*So, you can configure to pick that number you selected and store it on a table.

That's what I did, in my case I want to pick that number and search in a Excel sheet this and fill the respective value.

If your number is inside a WebTable you can do the following (I don't know if it works, I'm don't have much knowledge on QTP):

*Do a CheckPoint in the table and select only the field that appears the random ID.
*Parameterize that field, to receive the table that you stored the rendom ID.

Well, sorry for the long post, I hope that can help you to solve that. Anyway, if you still has some doubts send me a message. Good luck Smile
Reply
#6
Solved: 10 Years, 9 Months, 1 Week ago
Thanks guilherme_br. I will try those steps.

I did check the link out, but the problem is that in my case the ID number is not a link. Its just a simple text.

I have attached two files. One that shows how the survey looks like and the other showing the table that QTP captures.

I want QTP to know that a new survey has been created and also knows that the delete or edit button next to it is the right one.

Hope it is more clear now?


Attached Files Image(s)
       
Reply
#7
Solved: 10 Years, 9 Months, 1 Week ago
Okei, now am getting the output value in the runtime datatable as attached.
The challenges now are:

- How do I make sure that this id exists in the WebTable for example?
- Whenever a new survey is created, a new edit and delete buttons are created also. Each has a link with the id inside. How do I make sure that it is clicking the right delete button for example? Right now it is clicking delete on a certain row only. Here is my crappy code from a crappy script writer Big Grin
'Adding survey here
Code:
Browser("Web Single Sign On").Page("ad1Domain").Link("Quick Surveys").Click
Browser("Web Single Sign On").Page("ad1Domain_2").Link("Create new survey").Click
Browser("Web Single Sign On").Page("ad1Domain_3").WebEdit("T2200210021164289598977{action").Set "13.09.2009"
Browser("Web Single Sign On").Page("ad1Domain_3").WebEdit("T2200210021164289598977{action_2").Set "13.09.2011"
Browser("Web Single Sign On").Page("ad1Domain_3").WebEdit("T2200210021164289598977{action_3").Set "Automator"
Browser("Web Single Sign On").Page("ad1Domain_3").WebEdit("T2200210021164289598977{action_4").Set "Automation?"
Browser("Web Single Sign On").Page("ad1Domain_3").Link("ADD SURVEY").Click
'Taking output value

Code:
Browser("Web Single Sign On").Page("ad1Domain_4").WebElement("222").Output CheckPoint("222")

Browser("Web Single Sign On").Page("ad1Domain_4").Check CheckPoint("ad1Domain")
Browser("Web Single Sign On").Page("ad1Domain_4").Link("Back to main").Click
'Deleting the survey, of course the wrong one!

Code:
Browser("Web Single Sign On").Page("ad1Domain_5").WebElement("DELETE").Check CheckPoint("DELETE")

Browser("Web Single Sign On").Page("ad1Domain_5").Link("DELETE").Click
Browser("Web Single Sign On").Dialog("Microsoft Internet Explorer").Activate
Browser("Web Single Sign On").Dialog("Microsoft Internet Explorer").Check CheckPoint("Microsoft Internet Explorer")
Browser("Web Single Sign On").Dialog("Microsoft Internet Explorer").WinButton("OK").Click


Attached Files Image(s)
   
Reply
#8
Solved: 10 Years, 9 Months, 1 Week ago
*I think that everytime you create a new survey, it add a line in your WebTable, right? If that so, it's gonna be hard to check this. I think you could do some if's getting the number of the created survey from the table and trow to a variable. Based on your image, the new survey always gonna be on cell "A2" on your table.

*Well, for this one I can't imagine what you could do, I guess that you can check the link and somehow pick that id and do some if's (again) comparing with the output value.

Well, this probably can't help you so much. But if I had to do this I'll try something like that. Sorry if I can't help you more than that right now
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get numbers inside all webelements in webtable and sort them pradeep537 1 2,567 08-04-2016, 01:24 AM
Last Post: Ankur
  Create a random number starting with an alphabet QTPmate 4 3,853 07-31-2014, 09:29 AM
Last Post: QTPmate
  Random Values from Drop-Down profqa 5 5,701 12-06-2013, 09:01 AM
Last Post: basanth27
  GCD of N numbers Venkat`s 1 1,918 10-17-2013, 08:58 PM
Last Post: Parke
  Creating Random String SomeIntern 0 4,774 08-21-2013, 09:10 PM
Last Post: SomeIntern

Forum Jump:


Users browsing this thread: 1 Guest(s)