領測軟件測試網
使用QuickTest Professional(QTP)需要掌握的小技巧
17、Q: 如何參數化link
Browser("Browser").Page("Page").Sync Browser("Browser").Navigate "http://www.51testing.com/cgi-bin/index.php" Browser("Browser").Page("51Testing軟件測試論壇---軟件測試,軟件質量工程師").Sync
Set tags=Browser("Browser").Page("51Testing軟件測試論壇---軟件測試,軟件質量工程師").Object.links Dim i,j, arr() i=0 For Each element in tags If Ucase(element.tagname)="A" and left(element.InnerText,1)="[" Then ReDim Preserve arr(i+1) arr(i)=element.InnerText i=i+1 end if Next
For j=0 to i Browser("Browser").Page("51Testing軟件測試論壇---軟件測試,軟件質量工程師").Link("[ 版主討論區 ]").SetTOProperty "Text",arr(j) Browser("Browser").Page("51Testing軟件測試論壇---軟件測試,軟件質量工程師").Link("[ 版主討論區 ]").Click Browser("Browser").Back Next |
這段代碼先是打開一個空的頁面,然后輸入url.到達論壇首頁。然后得到所有版面的名稱,也就是link的名稱,存到數組里面。然后使用SetTOProperty更換錄制時候錄下的link的屬性,這時候再click。
18、Q:QTP 在Debug狀態,在Export View 區域不能寫入任何東西
A: 如果你的目的是在debug過程中修改已執行過的命令,可以在Debug view的Command中執行命令,如重新執行已經執行過的命令,修改變量的值等等。
如:Window("Flight Reservation").WinEdit("Name:").Set "51testing"
已經執行,如果現在想修改“51testing”為“testing”,可以在command中執行
Window("Flight Reservation").WinEdit("Name:").Set "testing"
19、Q:動態變化值如何獲取
A:VAL=Browser("歡迎使用我的工作臺").Page("歡迎使用我的工作臺").Frame("managePlace_7").WebRadioGroup("userAccountId_0").GetROProperty("Value")
Browser("歡迎使用我的工作臺").Page("歡迎使用我的工作臺").Frame("managePlace_7").WebRadioGroup("userAccountId_0").select val
20、Q:如何一一獲得Table中 某欄 link 的 text?
A:通過上面link 的學習. 我終于融會貫通,完成了我的問題: 與大家共享:
Browser("Login").Page("Page").Frame("contents").ViewLink("treeview").Image("Tplus").Click Browser("Login").Page("Page").Frame("contents").ViewLink("treeview").Image("Tplus_2").Click Browser("Login").Page("Page").Frame("contents").ViewLink("treeview").Link("開課設置").Click Browser("Login").Page("Page").Frame("main").WebList("drpStatus").Select "任意" Browser("Login").Page("Page").Frame("main").WebButton("查找").Click Browser("Login").Page("Page").Sync
Dim finded,findCode,Nowout 'define a constrat for find findCode = 110901 finded = false
Function MaxPage(pageString) 'msgbox pageString Dim ilen,i,j ilen = len(pageString) i=ilen While i>0 j = mid(pageString,i,1) 'msgbox j If instr("123456789",j)>0 Then MaxPage = j 'msgbox MaxPage Exit function End If i=i-1 Wend End Function
Dim trowcount,maxp trowcount = Browser("Login").Page("Page").Frame("main_8").WebTable("開課代碼").RowCount msgbox "Rowcount: "&trowcount Nowout = Browser("Login").Page("Page").Frame("main_8").WebTable("開課代碼").GetCellData(trowcount,1) Nowout = trim(Nowout) maxp = MaxPage(Nowout) msgbox "max page: "& maxp
Dim nowPage,checkid For nowPage = 1 to maxp If finded Then Exit for End If ' link to the 當前所需page If nowpage>1 Then Browser("Login").Page("Page").Frame("main_8").Link("[2]").SetTOProperty "Text","["&nowpage&"]" Browser("Login").Page("Page").Frame("main_8").Link("[2]").Click Browser("Login").Page("Page").Sync end if
' Get the rowcount of table in now page trowcount = Browser("Login").Page("Page").Frame("main_8").WebTable("開課代碼").RowCount msgbox "Rowcount: "&trowcount
'link every record in the table of the page for i = 2 to trowcount - 2 Nowout = Browser("Login").Page("Page").Frame("main_8").WebTable("開課代碼").GetCellData(i,2) 'msgbox i&": "&Nowout
checkid = "dgCourse:_ctl" &(i+1)& ":_ctl0" Browser("Login").Page("Page").Frame("main_8").WebCheckBox("dgCourse:_ctl3:_ctl0").SetTOProperty "name",checkid Browser("Login").Page("Page").Frame("main_8").WebCheckBox("dgCourse:_ctl3:_ctl0").Set "ON"
Browser("Login").Page("Page").Frame("main_8").Link("0901").SetTOProperty "Text",Nowout Browser("Login").Page("Page").Frame("main_8").Link("0901").Click Browser("開課設置詳細信息").Page("開課設置詳細信息").Sync 'wait(1) msgbox "begun" msgbox findCode msgbox Nowout msgbox "finished" If trim(findCode) = trim(Nowout) Then finded = true msgbox "find is ok!" wait(2) Exit for End If Browser("開課設置詳細信息").Close Browser("Login").Page("Page").Sync next
Next |
文章來源于領測軟件測試網 http://www.kjueaiud.com/