关于使用webtable中ChildItem方法时报错之解决方案

来源:互联网 发布:windows病毒弹窗音乐 编辑:程序博客网 时间:2024/04/29 20:01

运行时总报错:缺少对象

myobj =Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").ChildItem(2,2,"WebElement",0)
myobj.fireevent "ondblclick"
运行时总报错:缺少对象
***************************************************************************

vbs语法使用不当,例如

dim myobj --把myobj定义成了变量 --去掉这个定义

set myobj = Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").ChildItem(2,2,"WebElement",0)

 

这样写是会报错的,正确的写法去掉dim myobj定义


***************************************************************************

使用GetCellData(Row, Column)里面的Row和 Column,  对ChildItem (Row, Column, MicClass,0) 进行操作时,如果出现不了我们期望的结果,这说明最后一个参数的值不能是0.。我就遇到了这样的情况,使用ChildItemCount (Row, Column, “WebElement”) 得到的值是4,只有使用ChildItem (Row, Column, “WebElement”,2)  才可以得到我要的人结果。当然,如果使用ChildItemCount (Row, Column, MicClass)得到的返回值是1,那么 ChildItem 的值只能是0 了
***************************************************************************
如果使用ChildItemCount(Row, Column, MicClass)得到的返回值是0, 那么说明我们写的ChildItemCount里的某一个或某几个参数有误(类型错误或参数的值有错误)。 一般不会写错MicClass 的值(注意不要漏掉双引号)。因此最大的可能是Row的 Column 的1取值有误。 我们可以使用RowCount 方法得到 WebTable 的总行数,然后使用ColumnCount 函数得到WebTable 某行的列数。最后遍历循环每一行和每一列,看看到底Row的 Column 分别取什么值才能得到我们需要进行操作的数据。
    注意:ColumnCount 后面必须要加一个表示行号的参数,因为在一个WebTable 里面,不同的行可能有不同的列数(如最后一行只有2列,前面所有的行都有4列)。

***************************************************************************

于是修改代码如下:

For i=1 to Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").RowCount
colcumCnt=Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").ColumnCount(i)
For j=1 to colcumCnt
  count=Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").ChildItemCount(i,j,"WebElement")
        mytext="i:"+Cstr(i)+" j:"+Cstr(j)+" 有"+Cstr(count)+"个WebElement"
        MSGbox mytext
Next

Next
set myobj=Browser("chinamobile.com - Welcome").Page("chinamobile.com - 个人工作台").WebTable("项目名称").ChildItem(2,1,"WebElement",0)
myobj.fireevent"ondblclick"

原创粉丝点击