2013-04-18 39 views
0

這發生在testcomplete版本9.20中,並針對firefox 19.0.2進行測試。在testcomplete中調用jquery時VBscript失敗

第一個腳本文件稱爲test,它包含以下行:

'USEUNIT CommonFunctions 
Public Function test() 
    Call expandTree() 
End Function 

其他腳本文件被命名爲CommonFunctions具有這樣的功能:

Public Function expandTree() 
    Set foo = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").click() 
End Function 

當我運行腳本的自動化文件給出以下錯誤:

Microsoft VBscript runtime error. 

Object doesn't support this property or method:"contentDocument.Script.jQuery(...).Click'' 

Error location: 
Unit:"ContentSuite\Content\Script\CommonFunctions" 
Line:3972 Coloumn2 

如果將jquery放在同一個文件中,則不會發生同樣的錯誤。也就是說,如果我運行這個它會正常工作,然後單擊將很好地工作:

Public Function test() 
    Set foo = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").click() 
End Function 
+0

如果沒有看到完整的代碼,很難說。你能否編輯你的問題,幷包含兩個函數的代碼? – Helen

+0

添加更多的細節,謝謝你的評論 – user2295001

+1

還沒有足夠的信息。請告訴我們TestComplete的版本以及您使用的瀏覽器。另外,如果直接從CommonFunctions單元運行,請檢查是否可以執行expandTree例程。 –

回答

0

首先,當前的代碼使用DOM click方法,它沒有返回值,所以你需要刪除Set foo =

錯誤可能是jQuery選擇器沒有找到任何匹配的對象。請嘗試檢查jQuery功能結果length屬性:

Set links = Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose") 
If links.length > 0 Then 
    links.click 
Else 
    Log.Error "Object not found." 
End If 

但其實沒有必要在這裏使用jQuery,因爲TestComplete具有內置QuerySelector方法:

Set obj = Aliases.tree.QuerySelector("li[data-nodeid='sites'] a.openClose") 
If Not obj Is Nothing Then 
    obj.Click 
Else 
    Log.Error "Object not found." 
End If 
+0

感謝您的幫助helen!現在它工作正常,沒有任何問題 – user2295001

0

我覺得現在的問題可能與您嘗試調用jQuery方法返回的對象的方法單擊的方法有關。由於此方法返回一個集合,因此請在單擊它之前嘗試獲取特定對象:

Public Function expandTree() 
    Aliases.tree.contentDocument.Script.jQuery("li[data-nodeid='sites'] a.openClose").get(0).click() 
End Function