How to create dropdown list box using QTP or OTA API (1954 Views)
Reply
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 1 of 14 (1,954 Views)
Accepted Solution

How to create dropdown list box using QTP or OTA API

I need to allow the user to choose an item from a list of items. Based on the user's selection, I will have to run a new script. Is it possible to create a dropdown list box using QTP, if not how to use OTA API to create a combobox or dropdown list box.
Honored Contributor
Posts: 933
Registered: ‎04-22-2009
Message 2 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Where do you want to display the list from, QTP?


Mark Smith.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 3 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

I need to run the QTP scripts on remote machines. A list has to be generated from a spreadsheet on the server and should be displayed on the client machine.(list is dynamic but not necessary) The list has to be generated in the QTP.
Honored Contributor
Posts: 933
Registered: ‎04-22-2009
Message 4 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Simple way:

save this as drop-down.htm

===================================


My Page







========================================

From QTP run this:

SystemUtil.Run "IEXPLORE.EXE","C:\Temp\Drop-Down.htm","","open"

While Browser("name:=My Page").Page("title:=My Page").WebList("name:=mydropdown").GetROProperty("selection") = "Select Car"
Wend


Mark Smith.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 5 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Thanks a lot Mark, that was so cool.
But is there a way that I can dynamically populate the .htm file with runtime data?

Also, I have to generate several of the .htm files with each having data of 100 items, what is the best approach to create them?
I have all the data in a spreadsheet.
can I use qtp to generate if so how?

Thanks a ton again.

Sam
Honored Contributor
Posts: 933
Registered: ‎04-22-2009
Message 6 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

First part you would have to generate the HTML from within QTP, here's an example using the previous form:

============================================
Car1 = "BMW"
Car2 = "Audi"
Car3 = "Ford"



sHtml = ""
sHtml = sHtml & "

Car Selector


"
sHtml = sHtml & "
"
sHtml = sHtml & ""
sHtml = sHtml & "
"
sHtml = sHtml & "Check Here to Continue Script"
sHtml = sHtml & "
"
' Define Dialog size
iWidth = 710
iHeight = 800
' Display the IE Dialog Screen
'Get screen size
' WMI code by permission of www.intelipro.co.uk
Set oWMIService = GetObject("Winmgmts:\\.\root\cimv2")
Set cItems = oWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each oItem in cItems
iScrWidth = oItem.ScreenWidth
iScrHeight = oItem.ScreenHeight
Next
'Show it
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "about:blank"
oIE.Document.body.innerHTML = sHtml
oIE.Visible = True
'oIE.Quit
Set oIE = Nothing

' Process returned data
With Browser("openURL:=about:blank").Page("url:=about:blank")
While .WebCheckBox("name:=cont").GetROProperty("checked") = 0
Wend
vStatus = .WebList("name:=myWebList").GetROProperty("selection")
End With
Browser("openURL:=about:blank").Close
============================================

2nd part getting the data in may be a little trickier, let me know if this is OK and we can discuss the 2nd part.


Mark Smith.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 7 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Thanks Mark, Thats a gr8 piece of code.
I could understand almost of it.
Can you explain the second part?

Thanks a lot again.
Honored Contributor
Posts: 933
Registered: ‎04-22-2009
Message 8 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

2nd part creates an Internet Explorer object and sets some internal properties.

I also played with the code and found you can populate the values dynamically using an array, if you add another value to MyArray you should see it populated in the drop-down:


============================================
MyArray = Array("Audi","BMW","Ford","Saab")


sHtml = ""
sHtml = sHtml & "

Car Selector


"
sHtml = sHtml & "
"
sHtml = sHtml & ""
sHtml = sHtml & "
"
sHtml = sHtml & "Check Here to Continue Script"
sHtml = sHtml & "
"
============================================


Mark Smith.

Advisor
Posts: 33
Registered: ‎10-09-2009
Message 9 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Thanks a lot Mark! Your comments were very helpful.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 10 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Thanks to Mark.
sol was apt.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 11 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Hello Mark,

Was wondering how to get the option value provided along with the item for the dropdown list. for example in


My Page








what should be the QTP statement to get the value of A for Audi or B for BMW?

tried below statement but it would still give Audi.
Browser("openURL:=about:blank").Page("url:=about:blank").WebList("name:=myWebList").GetROProperty("value")

Also, I tried using a button with the below statement but I was unable to fetch the value of button click or submission. QTP is unable to identify the object as such, even though the name of the object are the same.

used below code for button instead of checkbox
sHtml = sHtml & "
"
sHtml = sHtml & ""

While Browser("openURL:=about:blank").Page("url:=about:blank").WebButton("type:=submit").GetROProperty("checked") = 0
Wend
or
While Browser("openURL:=about:blank").Page("url:=about:blank").WebButton("name:=submit Query").GetROProperty("checked") = 0
wend

Thanks
Sam
Honored Contributor
Posts: 933
Registered: ‎04-22-2009
Message 12 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Sam, here is something I use in my Framework. It uses a CheckBox instead of a Button but still has the same effect.

I added a bit to the end to show you how to interrogate the WebList:

============================================
sHtml = ""
sHtml = sHtml & "

Select An Option


"
sHtml = sHtml & "
"
sHtml = sHtml & "

Select Status

"
sHtml = sHtml & "
"
sHtml = sHtml & ""
sHtml = sHtml & "
Check Here to Continue Script"
sHtml = sHtml & "
"
' Define Dialog size
iWidth = 710
iHeight = 400
' Display the IE Dialog Screen
'Get screen size
' WMI code by permission of www.intelipro.co.uk
Set oWMIService = GetObject("Winmgmts:\\.\root\cimv2")
Set cItems = oWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each oItem in cItems
iScrWidth = oItem.ScreenWidth
iScrHeight = oItem.ScreenHeight
Next
'Show it
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "about:blank"
oIE.Document.body.innerHTML = sHtml
oIE.Toolbar = False
oIE.StatusBar = False
oIE.MenuBar = False
oIE.Height = iHeight
oIE.Width = iWidth
oIE.Top = (iScrHeight-iHeight)/2
oIE.Left = (iScrWidth-iWidth)/2
oIE.Visible = True

' Process returned data
With Browser("openURL:=about:blank").Page("url:=about:blank")
While .WebCheckBox("name:=cont").GetROProperty("checked") = 0
Wend
' Get Selected Value
vSel = .WebList("name:=kdfWebList").GetROProperty("selection")
' Get All values
vTmp = .WebList("name:=kdfWebList").GetROProperty("all items")
End With

oIE.Quit
Set oIE = Nothing

MsgBox "Selected Value: " & vSel

vTmp1 = Split(vTmp,";")
vAll = vbCrLf
For i = 0 To UBound(vTmp1)
vAll = vAll & vTmp1(i) & vbCrLf
Next
MsgBox "All Values: " & vAll
============================================

Mark Smith.
Advisor
Posts: 33
Registered: ‎10-09-2009
Message 13 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

Thanks Mark!
Occasional Visitor
Posts: 1
Registered: ‎03-22-2010
Message 14 of 14 (1,954 Views)

Re: How to create dropdown list box using QTP or OTA API

1. From ServerSide (In c#)

To change ListBox to DropDownList just change the Rows property of the ListBox with â 1â Then it will behave as the Dropdown list in UI.
â ListBox1.Rows = 1;

For the reverse Add
â DropDownList1.Attributes.Add("size", "3");

2. In ClientSide (By Javascript)
DropDownList & Listbox Both rendered as select in the browser differentiate in their size property. So to change the UI of DropDownList to ListBox just change this property





<script type="text/javascript">
function ToggleView()
{
document.getElementById('ListBox1').size = 1; // This will Change from listBox to Dropdown List.
document.getElementById('DropDownList1').size = 3;// This will Change from Dropdown List to listBox.
}
</ script>


A small may be useful idea can be: Save the page space by showing the options in a DropDownList & on mousover change it to listbox & again on mouseout do the reverse.
Here is the sample code


onmouseout ="javascript&colon;document.getElementById('ListBox1').size = 1">
< asp:ListItem>Option 1
< asp:ListItem>Option 2
< asp:ListItem>Option 3

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.