1

誰かがこれに対する解決策を提案できれば、非常に感謝しています。

各値がアカウントを表す Web リストを含むページでブラウザーが開かれることを期待している単純な関数があります。アカウントが選択されると、その製品 (存在する場合) が表示されます。

関数の目標は、製品 (最初に見つかったもの) を含むアカウントのインデックスを取得することです。何もない場合は -1 を取得します。

何が原因なのかわからない問題は、関数をデバッグしているときに関数が正しい結果を返すことです。つまり、F10 を使用してコードを段階的に実行すると、間違った結果が返されます。定期的に実行します (F5)。この動作は一貫しており、関数は実行の種類ごとに毎回同じ結果を取得します。つまり、関数がランダムな回答を返すだけのバグではありません。

これは機能です:

' @return: a random account index with products if one exists
' otherwise returns -1
Public Function getRandomAccountWithProducts()
    On Error Resume Next


    Set Page1 = Browser("micclass:=browser").Page("micclass:=Page") 
    Set br = Browser("micclass:=Browser")   

    originalURL = br.GetROProperty("URL")

    br.Navigate Environment.Value("SOME URL") & "REST OF URL"
    br.Sync 


    Page1.WebList("name:=accountId").Select "#1"
    br.Sync 

    ' Display only products
    Page1.WebRadioGroup("name:=name0").Click
    Page1.WebList("name:=name1").Select "Display None"
    Page1.WebList("name:=name2").Select "Display None"
    Page1.WebButton("value:=Apply","visible:=True").Click

    ' Init
    numOfAccounts = Page1.WebList("name:=accountId").GetROProperty("items count") - 1

    If numOfAccounts < 1 Then
        getRandomAccountWithProducts = -1
        Reporter.ReportEvent micFail, "Number of accounts","There are no accounts. No account with products exists"
        Exit Function
    End If

    hasProducts = false
    accountIndex = 1

    ' Get account with products
    While ((Not hasProducts) AND (accountIndex =< numOfAccounts))

        ' Return account if has products
        If Page1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5) Then
            hasProducts = true
        End If

        If (Not hasProducts) Then                                   
            accountIndex = accountIndex + 1
            Page1.WebList("name:=accountId").Select "#" & accountIndex              
        End If
    Wend

    br.Navigate originalURL

    Set Page1= Nothing
    Set br = Nothing

    ' If no account has products, report and exit, else return selected account index
    If Not hasProducts Then
        Reporter.ReportEvent micFail,"Accounts","No account has products."
        getRandomAccountWithProducts = -1
    Else 
        getRandomAccountWithProducts = accountIndex
    End If



    If  Err<>0 Then
        errorMessage =  "Error number: " & Err.Number & vbNewLine & "Error description: " & Err.Description & vbNewLine & "Error source: " & Err.Source
        Reporter.ReportEvent micFail,"Run Time Error",errorMessage
        Err.Clear
    End If

    On Error GoTo 0
End Function

Pentium 4、3.2 GHZ、2 GB RAM、Win XP、SP 3、IE 7、QTP 10.0 Build 513 で実行しています。

ありがとう!

4

2 に答える 2

0

all itemsプロパティの使用を検討しましたか?

AllItems = Page1.WebList("name:=accountId").GetROProperty("all items")
SplitItems = Split(AllItems, ";")
Found = False
For i = 0 To UBound(AllItems)
    If AllItems(i) = "<product>" Then
        Found = True 
        Exit For
    End If
Next
于 2010-06-02T11:14:25.863 に答える
0

Jontyのおかげで解決策が見つかりました。

問題は次のセクションにありました。

  ' Get account with products

    While ((Not hasProducts) AND (accountIndex =< numOfAccounts))

        ' Return account if has products
        If Page1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5) Then
            hasProducts = true
        End If

        If (Not hasProducts) Then                                   
            accountIndex = accountIndex + 1
            Page1.WebList("name:=accountId").Select "#" & accountIndex              
        End If
    Wend

初めてループに入ったとき、アカウントには実際には製品がなかったため、明らかに何も認識されませんでした。したがって、accountIndex が 1 つ増加し、対応するアカウントが Web リストで選択されました。

いいえ、ここに問題があります。select メソッドによってページが更新されPage1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5) 、Web リストが読み込まれる前に条件が評価されたため、false が返されました。

私はそのオプションを検討しましたが、Exist(5) がそのトリックを行うべきだと (明らかに間違って) 考えましたが、予想とは異なる動作をしているようです。

ありがとう、

アロン

于 2010-06-02T12:12:02.367 に答える