如果捕获HTMLTable里普通的文本?
在一个表格里,robot里使用Object Property方法可以捕获出其类型为HTMLTable,表格中如果某列是带链接的数据,那么使用对象属性工具捕获时是HTMLLink,但是如果表格的某列就是普通的文本,那么捕获出的还是HTMLTalbe而不是Label。。。这样如果使用sqafindobject(),sqagetproperty()等函数时就无法定位到制定行指定列。。。请问可以有什么方法解决吗?我的目的就是想捕获出某行非链接的列的内容,即一个普通的单元格中内容。
自己顶下!
我看到过去的帖子里给过简单的例子提示,就是说使用:sqagetproperty("Type=HTMLTable;Name=...","columns(1).count",value)
这个属性是没有的,应该怎么写函数获取相关值,又经验的请给个提示。。。谢了:)
新一周了,自己顶下!
帖子已经发出好2,3天了,一直没人回复!新的一周开始,希望有经验的人事多发表意见,给出问题的解决思路。 你先把innerhtml属性读出来,
每行数据是用<TR******/TR>来区别
每个Cell的数据是用<TD ****/TD> 来区别
或者你直接读InnerText属性值,数据分行的。。
感谢回复
请问楼上的意思是要让我解析取出的所有字符吗?html语言我到是还比较熟悉,但是具体到怎么把这一大串字符解析出来还是不清楚。需要借助外部开发工具吗?然后引.dll?感觉有些复杂了。。。请再具体讲下!:) Dim WinCaption as stringDim 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 如果你使用的是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") 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", youcan 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
感谢回复!
篇幅很长,我仔细看看了。不过GetFieldCount这个为什么在我这里不是关键字颜色,需要装什么插件吗?类似的命令函数还有SQAGetPropertyAsArray()等,都不是关键字的颜色。。。
再有想问下您说的这个RRAFS框架是什么意思?能再具体说下吗?我的用的Robot版本为v7.0.0.0 关于RRAFS,你看看这里:
http://blog.csdn.net/piaocl/archive/2004/05/07/19552.aspx
读取文本 有两种方法:
1:通过InnerText来读,但是字段值之间没有分割
2:通过InnerHTML 来分析,需要使用<TR<TD来解析
3:通过HtmlTableVP的objectdata来解析
4:直接通过RRAFS的库函数来解析。 RRAFS看这里
http://blog.csdn.net/piaocl/archive/2004/05/07/19552.aspx
非常感谢!
真是高人,我先看看了,不会的继续请教!多谢! 可以用SQAGetChildren()来获取,然后在子对象数组中进行判断读取
页:
[1]