51Testing软件测试论坛

标题: qtp如何设置下拉框取值 [打印本页]

作者: liujun_11    时间: 2012-11-6 15:09
标题: qtp如何设置下拉框取值
初学QTP,使用QTP自带c/s订票系统想实现登陆-》订票,登陆action执行一次,订票操作执行多次,每次执行是按照下拉框值的顺序进去取值,例如fly from 下拉框的值为Denver、Frankfurt、London、Los Angeles、Paris每次订票操作一次取值,附脚本如下,目前只做到了取下拉框第一个值进行订票,没有进行循环,请高手指教
ation1
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Agent Name:").Type  micTab
Dialog("Login").WinEdit("Password:").SetSecure "50986ace3f22671a4e031ae82c90de713b9a304c"
Dialog("Login").WinEdit("Password:").Type  micReturn

action2

Window("Flight Reservation").Activate
Window("Flight Reservation").WinObject("Date of Flight:").Type "111112"
itemscount = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty ("items count")
For i = 0 to itemscount -1
Window("Flight Reservation").WinComboBox("Fly From:").Select i '用序号来选择
print window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
Next

itemscount1 = Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty ("items count")
For e = 0 to itemscount1 -1

Window("Flight Reservation").WinComboBox("Fly To:").Select  e
Next

Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select RandomNumber("p_Item")
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").Activate
Window("Flight Reservation").WinEdit("Name:").Set "aa"
Window("Flight Reservation").WinButton("Insert Order").Click

wait 10
msgbox window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
作者: liujun_11    时间: 2012-11-6 15:17

作者: joykao    时间: 2012-11-6 15:54
这个参数化就搞定了吧。。。。
作者: liujun_11    时间: 2012-11-6 16:18
回复 3# joykao


参数化确实可以做,但是   我是想通过写循环语句来实现,
作者: louqqson008    时间: 2012-11-6 17:06
本帖最后由 louqqson008 于 2012-11-6 17:30 编辑

改下这个试试

action2

Window("Flight Reservation").Activate
Window("Flight Reservation").WinObject("Date of Flight:").Type "111112"
LISTitems=Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty ("all items")  '读取下拉框中所有值
itemscount =LISTitems.count
For i = 0 to itemscount -1
Window("Flight Reservation").WinComboBox("Fly From:").Select  LISTitems(i)      
Next

但是想说句  像上面这样循环没有意义的,只是把下拉框中的值循环了下,输入给action中的值是同一个的
作者: joykao    时间: 2012-11-6 17:42
回复 4# liujun_11


    SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "mercury"
Dialog("Login").WinEdit("Password:").set "mercury"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Activate
Window("Flight Reservation").ActiveX("MaskEdBox").Type "110712"
itemscount = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty ("items count")
For i = 0 to itemscount -1
Window("Flight Reservation").WinComboBox("Fly From:").Select i '用序号来选择
'print window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
itemscount1 = Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty ("items count")
For e = i to itemscount1-1
Window("Flight Reservation").WinComboBox("Fly To:").Select  e
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "Aa"
If i=0 and e=0  Then
        Window("Flight Reservation").WinButton("Insert Order").Click
        else
Window("Flight Reservation").WinButton("Update Order").Click
End If
Next
Next
Window("Flight Reservation").Close


试下吧。。。我调试过没问题
作者: zcl432106    时间: 2013-10-30 16:21
嗯嗯,学习了,楼上的赞一个




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2