感谢您查看此问题。只是想知道是否有一种在运行时创建描述对象模型的最佳方法。我的代码失败了
Object doesn't support this property or method: 'Browser(...).page(...).WebButton'
FunctionCreateDescObjAt_RunTime(StrBrowserNme,StrBrwsrTitle,StrObject,StrPgeNme,StrPgtitle,StrObjectName,index)`
'create a description object for Browser & Page`
Set WebBrwsrDesc= Description.Create
WebBrwsrDesc("application version").value= "Internet Explorer.*"
If StrBrowser<>"" Then
WebBrwsrDesc("name").value=StrBrowserNme
WebBrwsrDesc("title").value=StrBrwsrTitle
End If
Set WebPageDesc= Description.Create
WebPageDesc("name").value=StrPgeNme
WebPageDesc("title").value=StrPgtitle
' 'Based on the type of object, execute the condition`
Select Case StrObject`
Case "WebButton"
Set WebBtnDes= Description.Create
WebBtnDes("html tag").value="INPUT"
WebBtnDes("name").value=StrObjectName
WebBtnDes("micclass").value="button"
WebBtnDes("index").value=index
'Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
Browser(WebBrwsrDesc).page(WebPageDesc).WebButton(WebBtnDes).click
end select
End Function
我正在通过行动打电话
CreateDescObjAt_RunTime "Account Login","Your Store", "WebButton", "", "Account Login", "Login", ""
这是失败的。但是,如果我不评论这条线和&amp;评论问题行,它的工作原理
Browser("title:=.*","name:=.*").page("title:=.*","name:=.*").WebButton(WebBtnDes).fnWebButtonClick
你能用正确的方法帮助我吗?感谢
答案 0 :(得分:1)
如果您想设置通用浏览器和页面,只需使用类似于您评论过的行的语句:
Dim objPage : Set objPage = Browser("class:=browser").Page("title:=.*")
上面的行将创建一个可以使用的页面对象。
检查传递给您的函数的参数,以确保您正确识别浏览器和页面。
对于您想要在运行时创建的实际对象部分,您需要创建一个Description
对象,然后查找主对象的ChildObjects
(在这种情况下,您的页面)并将其存储到一个集合。之后,您可以检查是否找到了您的对象。所以你的Select Case
部分会是这样的:
Select Case StrObject
Case "WebButton"
' This is just a description of your object, not your actual object
Dim descButton : Set descButton = Description.Create
descButton("html tag").value="INPUT"
descButton("name").value=StrObjectName
descButton("micclass").value="button"
descButton("index").value=index
' In the following statement you are looking for all child objects
' of your page that matches with your description, and storing it
' into the collButton collection
Dim collButton : Set collButton = Browser("class:=browser").Page("title:=.*").ChildObjects(descButton)
If collButton.count > 0 Then ' Now you are checking if any object was found
' There are many ways to get the button object that you want.
' Here I'm just assuming you want the first one, but you could iterate
' into the collection to make sure you have the right one
Dim objButton : Set objButton = collButton(0) ' I'm getting the first item, which is in index 0 of your collection
objButton(0).Click ' This object already have the whole Browser().Page().WebButton() identified, so no need to use it
Else
MsgBox "No WebButton found. Please check your Description object"
End If
' Your other cases...
End Select
答案 1 :(得分:0)
Web按钮的MicClass不能是按钮。它应该是WebButton
'您正在使用以下
WebBtnDes("micclass").value="button"
应该是:WebButton
'无论如何描述描述对象
Set ObjButton=Description.Create
ObjButton("MiCClass").value="WebButton"
ObjButton("name").value=strButtonName
ObjButton("htmlid").value=strHtmlId
Set ObjButton= Browser().page().ChildObject(ObjButton)