Micro Focus QTP (UFT) Forums
Is there a way to select dynamic option of an object in run time? - 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: Is there a way to select dynamic option of an object in run time? (/Thread-Is-there-a-way-to-select-dynamic-option-of-an-object-in-run-time)

Pages: 1 2


Is there a way to select dynamic option of an object in run time? - joshasha - 10-16-2009

Hi everyone,

I am a new person using QTP to develop test script. I am writing the test script to verify adding some products with different options to a cart of web application. I wonder how to identify dynamic options of these products in run time. I used datatable with the column "ProductID" which is described as inputted parameter. It means that I only input the static Product ID from the datatable to "Search" field of web page and I want to execute the script to automatically select an option item in each group from the specified Product ID (not to select a specified option as below and I also don't want to input static options into datatable) then add it to the cart. Please help me find a way to solve it.

Here are some recorded scripts when using the Record functionality:

Code:
Browser("IE").Page("Shopping site").WebEdit("keywords").Set DataTable("ProductID", dtGlobalSheet)
Browser("IE").Page("Shopping site").Image("find our site").Click 8,5
Browser("IE").Page("Product").WebEdit("qty").Set "3"

'it means that I select the option item 1 from option group 1 "id[MGP915]"
Browser("IE").Page("Product").WebList("id[MGP915]").Select "Amber Color"
'it means that I select the option item 2 from option group 2 "id[MGP899]"
Browser("IE").Page("Product").WebRadioGroup("id[MGP899]").Select "OPT3522"
Browser("IE").Page("Product").Image("In Cart").Click 91,12
Browser("IE").Page("Product").Sync
Browser("IE").Close
'end script.

Many thanks to quick reply for this case.
BR


RE: Is there a way to select dynamic option of an object in run time? - azeem - 10-16-2009

Hi

Could you please attach the screen of your issue.

Thanks,
Azeem


RE: Is there a way to select dynamic option of an object in run time? - joshasha - 10-16-2009

Hi Azeem,

Thanks for your quick reply and I am sorry for making you confused when reading this topic with unclear issue.

Below is an example to add a product to cart (Each product has different options which we only see during run time)

Example:
Step 1. Launch to the website "http://www.lockersupply.com"
Step 2. Input a product code, such as LW1376, into Search field.
Step 3. Click on "Search" button.
Step 4. Select all options for the product if any (For example, select 3 options for Product "LW1376")
Step 5. Input a number into Qty field.
Step 6. Click on "Add to Shopping Cart" button

At Step #3, the number of options varies based on the product code, i.e. there is none, one, or more than one option for a product. So, I want to have a script which is able to automatically select all the possible options of a product, i.e. if a product has 4 options, then 4 of them should be chosen.

BR,
joshasha


RE: Is there a way to select dynamic option of an object in run time? - jsknight1969 - 10-17-2009

Can depend on the option object, but assuming its a checkbox list or something, you can do an item count (.GetROProperty("item count")) then do a loop to select each item (.GetItem(x)). Sorry I don't remember the exact code.

GL.


RE: Is there a way to select dynamic option of an object in run time? - basanth27 - 10-20-2009

Yes, thats the best approach.

1. First Find the Object ( I guess in your case it is a weblist ).
2. Find the number of items in the object ( getroproperty("itemscount") )
3. Use For loop to iterate between the count ( For i =1 to itemcount)
4. Select the item based on the index cummulatively (for eg : Select(i) )

Sample Code,

Code:
itemcount = Browser("IE").Page("Product").WebList("id[MGP915]").GetRoproperty("itemscount")

For i = 1 to itemcount
   Browser("IE").Page("Product").WebList("id[MGP915]").Select i
Next

Does this help ?
@Azeem - Can you explain your true intention behind the screenshot ?


RE: Is there a way to select dynamic option of an object in run time? - venkatbatchu - 10-20-2009

Hi,
with the below code u would be able to identify how many list box has been displayed dynamically
Code:
Browser("Lockers, Storage Lockers,").Page("Lockers, Storage Lockers,").WebEdit("keyword").Set ("LW1368")
Browser("Lockers, Storage Lockers,").Page("Lockers, Storage Lockers,").WebButton("Search").Submit
wait(10)
Set a=Description.Create
a("html tag").value="SELECT"
Set b=Browser("Lyon - Work Bench with").Page("Lyon - Work Bench with").ChildObjects(a)
c=b.count
msgbox c 'Here u will be able to identify how many attributes list has been displayed


Please find the attached Object Repository also , it may helpful to u
I am attaching OR.doc (As because this site is not accepting .tst files so i changed it to .doc , if u wnat to see this please change it to .tsr and upload it to your object repository)
Please let me know if u need any information apret from this...


RE: Is there a way to select dynamic option of an object in run time? - basanth27 - 10-20-2009

Woah..Woah..Woah...Mr.VenkatBatchu, would you please read the post clearly before stashing data into it ?

What is the necessity to attach a OR ?

Secondly, please please please, use formatted code.


RE: Is there a way to select dynamic option of an object in run time? - venkatbatchu - 10-20-2009

I have gone through the query and posted the query , please check it once again
Here for different number of product id's
Displaying list boxes will be vary (some times it will be 3 , some times it will be 2, some times it will not show any thing)
When it display the list boxes she has to select some values from those list boxes that is the requirement......
I have gone through the query and posted the my suggestion , please check it once again
Here for different number of product id's
Displaying of list boxes will be vary (some times it will be 3 , some times it will be 2, some times it will not show any thing)
When it display the list boxes she has to select some values from those list boxes that is the requirement...... (dynamically these number of list boxes will vary....)


RE: Is there a way to select dynamic option of an object in run time? - basanth27 - 10-21-2009

It is about the values in the listbox not the listbox itself.


RE: Is there a way to select dynamic option of an object in run time? - joshasha - 10-29-2009

I greatly appreciated your reply for solving my facing trouble. However, I have a little difficulty in indentifying the ID numbers of the option groups of an arbitrary product. In my previous post, I just simply chose the two option groups of product A, MGP915 & MGP899. In fact, the set of option groups varies for each product, i.e. each product has a different set of option groups (different types & number). So, Is there any way to identify this kind of dynamic data or we have to write a query in database to get the product's option groups?

Thanks all for your help,
joshasha.

Code:
itemcount = Browser("IE").Page("Product").WebList("xxxxxx").GetRoproperty("itemscount")
For i = 1 to itemcount
   Browser("IE").Page("Product").WebList("xxxxxx").Select i
Next