51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 5446|回复: 12
打印 上一主题 下一主题

[Robot] 如果捕获HTMLTable里普通的文本?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-9-5 14:12:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在一个表格里,robot里使用Object Property方法可以捕获出其类型为HTMLTable,表格中如果某列是带链接的数据,那么使用对象属性工具捕获时是HTMLLink,但是如果表格的某列就是普通的文本,那么捕获出的还是HTMLTalbe而不是Label。。。这样如果使用sqafindobject(),sqagetproperty()等函数时就无法定位到制定行指定列。。。请问可以有什么方法解决吗?
我的目的就是想捕获出某行非链接的列的内容,即一个普通的单元格中内容。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2008-9-5 15:15:57 | 只看该作者

自己顶下!

我看到过去的帖子里给过简单的例子提示,就是说使用:
sqagetproperty("Type=HTMLTable;Name=...","columns(1).count",value)
这个属性是没有的,应该怎么写函数获取相关值,又经验的请给个提示。。。谢了:)
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2008-9-8 09:27:03 | 只看该作者

新一周了,自己顶下!

帖子已经发出好2,3天了,一直没人回复!
新的一周开始,希望有经验的人事多发表意见,给出问题的解决思路。
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2008-9-11 08:27:01 | 只看该作者
你先把innerhtml属性读出来,
每行数据是用<TR  ******/TR>来区别
每个Cell的数据是用<TD ****/TD> 来区别

或者你直接读InnerText属性值,数据分行的。。
回复 支持 反对

使用道具 举报

该用户从未签到

5#
 楼主| 发表于 2008-9-11 10:03:26 | 只看该作者

感谢回复

请问楼上的意思是要让我解析取出的所有字符吗?html语言我到是还比较熟悉,但是具体到怎么把这一大串字符解析出来还是不清楚。需要借助外部开发工具吗?然后引.dll?感觉有些复杂了。。。请再具体讲下!:)
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2008-9-13 10:06:34 | 只看该作者
Dim WinCaption as string
    Dim ObjectRec as string     
    Dim Result As Integer
    Dim sinnerHtml as String   
    Dim Rows as integer
    Dim Cols as integer
    Dim CellText(1 to 1000,1 to 50) as String  
    Dim i,p as integer   
    Dim HTMLRows As integer
    Dim RowsText as string
   
   
    Result = WindowVP (Exists, "Caption=" & WinCaption, "VP=Window Existence")
    if Result = 0 then
        LogMessage "窗体 " & WinCaption & " 没有发现!!!",MainLog,Failed_MESSAGE
        exit Function
    End if   
   
    Window SetContext, "Caption=" & WinCaption , ""      
    Result = SQAGetProperty(ObjectRec,"innerHTML",sinnerHtml)   
    If Result = sqaSuccess Then   
        HTMLRows=GetFieldCount(sinnerHTML,0,chr(10))  '获取表格行数, '如果数据超过32767字符,Robot会死机
        if HTMLRows<=1 Then
            LogMessage "表格没有发现任何数据!!!",MainLog,Failed_MESSAGE
            exit Function
        end if
        
        '逐行读取           
        Rows=0        
        for i=1 to HTMLRows step 1        
            RowsText=GetField(sinnerHTML,i,chr(10))            
            
            IF (instr(RowsText,"<TR")=1) or (instr(RowsText,"<TR")=2) Then
                Rows=Rows+1  '表格每行
                Cols=0                          
            End if
            
            IF (instr(RowsText,"<TD")=1) Then        '查询出表格Cell的数据        
                Cols=Cols+1      
                p=instr(RowsText,"<A")                                
                if p>0 Then RowsText=mid(RowsText,p+2,len(RowsText)-p-1)                                                
               
                p=instr(RowsText,">")
                if p>0 then RowsText=mid(RowsText,p+1,len(RowsText)-p)
               
                p=instr(RowsText,"</A>")
                if p>0 then RowsText=mid(RowsText,1,p-1)
               
                p=instr(RowsText,"</TD>")
                if p>0 then RowsText=mid(RowsText,1,p-1)                 
                CellText(Rows,Cols)=RowsText
            End if
        Next i
    End If
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2008-9-13 10:14:08 | 只看该作者
如果你使用的是RRAFS框架,那么只要调用1个函数就可以,例子如下:
  Dim WinCaption as string
    Dim ObjectRec as string     
  Dim TableCell()  '表格数据
  ' WinCaption ="**** - Microsoft Internet Explorer"
  'ObjectRec ="Type=HTMLFrame;HTMLId=content;\;Type=HTMLTable;HTMLId=dgItemList"
  Window SetContext, "Caption=" & WinCaption , ""      
Call DDGGetGUIObjectData(ObjectRec ,TableCell(),"Contents")
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2008-9-13 10:24:23 | 只看该作者
Dim Result As Integer
    Dim DataArray(1 To 100,1 To 200) As String   
    Dim LineContents As String
    Dim i,j As Integer      
    Dim Dir1,File1, file2 As String
    Dim ColumnCount As integer
    Dim sColIndex As integer
    Dim sObjectName As String
   
        sObjectName="************************"
        Window SetTestContext, "CurrentWindow", ""
        SqaSuspendLogOutput   
        Result = HtmlTableVP (CompareData, sObjectName, "VP=HTMLTableData;Wait=2,2;ExpectedResult=FAIL")            
        SqaResumeLogOutput
        Window ResetTestContext, "", ""
            ' Robot provide one function to get "Actual Data" file, this file is always with full path and file name. the file name always contains "act" substring. (you can also get "expected data", but it means nothing.)
            ' But I found a problem. the Path is correct, but I cannot find the filename. it is very intersting! So we need find correct file for actual data.
        File1 = sqaVPGetActualFileName("HTMLTableData","grd")
            ' Because the filename is not correct, we need to get correct file name.
            ' This function is to get the DIR name from UNCname. Maybe, you don't use UNCName, you need to change the function. it is very simple.
        dir1 = GetDIRFromUNC(File1 )   
            ' The following find the acutal data file. Rebot support the pattern matching. it is lucky that there is only one file with the format "*act*.grd".
        File2 = Dir1 +  DIR(dir1+"*act*.grd")
            ' After get the file, we can open the file use "open", you  can open it as txt file.
            ' In the "*.grd" each line means each row in Listview Data.
            ' And there is one "tap" signal between each column. so it is very easy to manipulate the actual data.   
        if len(dir(File2))=0 Then        
            SqaConsoleWrite "获取表格(" & sObjectName  & ")数据失败!"
            exit sub
        end if
   
        Open File2 For Input As #99
        '$CStrings
            ' Here give you one example to get each column each row, and print the value into console log .
        Do until Eof(99) = -1
        Line input #99, LineContents
          j=j+1
                For i = 1 to ColumnCount
                    DataArray(j,i)=GetField(LineContents,i,"\t")
                    SqaConsoleWrite cstr(i) + "=" + GetField(LineContents,i,"\t")
                Next
       loop
        '$NoCStrings
        Close #99
      
       kill File2
回复 支持 反对

使用道具 举报

该用户从未签到

9#
 楼主| 发表于 2008-9-16 11:53:45 | 只看该作者

感谢回复!

篇幅很长,我仔细看看了。
不过GetFieldCount这个为什么在我这里不是关键字颜色,需要装什么插件吗?类似的命令函数还有SQAGetPropertyAsArray()等,都不是关键字的颜色。。。
再有想问下您说的这个RRAFS框架是什么意思?能再具体说下吗?我的用的Robot版本为v7.0.0.0
回复 支持 反对

使用道具 举报

该用户从未签到

10#
发表于 2008-9-18 02:22:38 | 只看该作者
关于RRAFS,你看看这里:
http://blog.csdn.net/piaocl/archive/2004/05/07/19552.aspx

读取文本 有两种方法:
1:通过InnerText来读,但是字段值之间没有分割
2:通过InnerHTML 来分析,需要使用<TR  <TD来解析
3:通过HtmlTableVP的objectdata来解析
4:直接通过RRAFS的库函数来解析。
回复 支持 反对

使用道具 举报

该用户从未签到

11#
发表于 2008-9-18 02:23:24 | 只看该作者
回复 支持 反对

使用道具 举报

该用户从未签到

12#
 楼主| 发表于 2008-9-18 11:39:09 | 只看该作者

非常感谢!

真是高人,我先看看了,不会的继续请教!多谢!
回复 支持 反对

使用道具 举报

该用户从未签到

13#
发表于 2009-9-18 16:44:16 | 只看该作者
可以用SQAGetChildren()来获取,然后在子对象数组中进行判断读取
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-21 16:25 , Processed in 0.075617 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表