Micro Focus QTP (UFT) Forums
Cascading heirarchy drop down list timing problem - 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: Cascading heirarchy drop down list timing problem (/Thread-Cascading-heirarchy-drop-down-list-timing-problem)



Cascading heirarchy drop down list timing problem - incite1321 - 10-09-2009

Hello,

I have a script that uses descriptive programming running against a web application. I am running into a problem with a set of drop down lists which are AJAX enabled. The load time of the lists often varies, and Qtp seems to be running too fast in some cases.

When a user selects an option from a drop down, a splash screen fills the page until the new set within the control has loaded. Choosing one of the options in a DDL determines the list in the box below it.

For example:
DDL 1: Options for Country. User Chooses "USA"
DDL 2: Loads in states or provinces within the USA, based on the previous selection. User Chooses "Alabama"
DDL 3: Loads all Cities from Alabama.... etc.

QTP seems to be trying to access the drop down before it finishes loading in the selections.

I have tried using Exists, WaitProperty, and Wait statements. The exists only verifies that the page loaded the drop down list, not the content of the list. WaitProperty seems only to be suited on checking if a selection has been made correctly. I have also tried searching the list to make sure that the entry i wish to select is in the "all items" property, but I cannot be sure that this check is run when the list has loaded. The only one of these that seems to be working as needed are the Wait statements. However, if the set takes too long to load, and my wait statement is too short, qtp will attempt to select an option from an empty list before it is loaded, and in the end, no option will be chosen at all.

The load time is fairly unpredictable at times, and since this action of choosing a drop down set is repeated hundreds (maybe thousands) of times within a single run of this script alone, I want to make sure it can run as quickly as possible, without making a wrong selection.

Here is the code I currently have in place:
Code:
Dim dpBrowser
dpBrowser = "micclass:=Browser"
Dim dpPage
dpPage = "micclass:=Page"

country = Trim(DataTable("country", dtLocalSheet))
state_province = Trim(DataTable("state_province", dtLocalSheet))
city = Trim(DataTable("city", dtLocalSheet))

<for loop here>
If country <> "" AND state_province <> "" AND city <> "" Then
    If Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").Exist(10) AND Instr(1, Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").getROProperty("all items"), country) <> 0 Then
        Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").Select country
        Wait(2)
    End If
    If Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlState_Province.*").Exist(10) AND Instr(1, Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlState_Province.*").getROProperty("all items"), state_province) <> 0 Then
        Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlState_Province.*").Select state_province
        Wait (2)
    End If
    If Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlcity.*").Exist(10) AND Instr(1, Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlcity.*").getROProperty("all items"), city) <> 0 Then
        Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlcity.*").Select city
        Wait (2)
    End If
End If
<some other code>
<save entry>
<end for loop>

Is a way to solve this problem, other than increasing the wait time?

Thank you,

Incite1321


RE: Cascading heirarchy drop down list timing problem - Ankur - 10-10-2009

You may also check for object.readystate property.


RE: Cascading heirarchy drop down list timing problem - jsknight1969 - 10-10-2009

How about a loop that constaintly checks for records in the dropdown to exists, waits if rowcount = 0

something like:
Code:
dim r
r=0
While r = 0
wait(5)
r = Browser("Browser").Page("Page").WebList("idType").GetROProperty("items count")
Wend

Might work....

PS: Properly formatted this time. I had to repost because I did not have rights to edit or delete my previous post.


RE: Cascading heirarchy drop down list timing problem - Ankur - 10-10-2009

I have done that for you. Thanks jsknight1969.


RE: Cascading heirarchy drop down list timing problem - incite1321 - 10-10-2009

Thank you both for your generous help. With some fiddling around, I was able to find a solution.

I tried your solution first, Ankur. However, the readystate for the drop down lists was always set to "complete". I do not quite know why, since I did not write the code for the web app page.

I went on to try jsknight1969's solution, and after a while, I was able to make it work.

Here is the code, modified from the example I gave above:
Code:
Dim dpBrowser
dpBrowser = "micclass:=Browser"
Dim dpPage
dpPage = "micclass:=Page"

country = Trim(DataTable("country", dtLocalSheet))
state_province = Trim(DataTable("state_province", dtLocalSheet))
city = Trim(DataTable("city", dtLocalSheet))

<for loop here>
If country <> "" AND state_province <> "" AND city <> "" Then
    Do While Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").GetROProperty("Items count") < 2
        Wait(1)
    Loop
    Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").Select country

    Do While Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlState_Province.*").GetROProperty("Items count") < 2
        Wait (1)
    Loop
    Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlState_Province.*").Select state_province

    Do While Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlcity.*").GetROProperty("Items count") < 2
        Wait (1)
    Loop
    Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlcity.*").Select city
End If
<some other code>
<save entry>
<end for loop>

"Items count" < 2, while a crude method, works quite well for properly measuring the timing. Again, thank you for the help.

Incite1321


RE: Cascading heirarchy drop down list timing problem - jsknight1969 - 10-12-2009

Sometimes the old tricks are the best tricks.

You could adapt the code to retrieve the number of items earilier, then compare that value to the current value to see if its different...

Code:
currcount = Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").GetROProperty("Items count")

While Browser(dpBrowser).Page(dpPage).WebList("html id:=.*ddlCountry.*").GetROProperty("Items count") <= currcount
wait(1)
Loop

This might be a little more "reusable" and would allow for the standard "select something" type messages in a drop down. You could also adapt it to recognize if the "select something" messages were removed when repopulated or a number of other conditions.

Glad you have a working solution now.