前段时间在做QTP脚本时,遇到一个问题,主要问题是给富文本框赋值的问题。在录制时可以录制到给富文框赋值的过程,但是当回放时却放不了。通过SPY查看,富文本框的outerHtml发现,设置富文本框实际上是一个BODY,而不是Edit,所以回放时赋值是失败的。那么如何解决这个问题呢?最终通过操纵IE DOM结构来完成了这一过程。废话不说了,直接上代码(注意使用Object时不能回放于fireFox中):
X i0HFV@0
*I;Pw6~7hX0'设置富文本框的值51Testing软件测试网M7re;c+y^9Q'^/JC+q
'bjtextAreaBelongFrameId:富文本框所在objFrame中的ID51Testing软件测试网)T&eTYQ#?n:Q
'textAreaValue:想在富文本框中所设置的值51Testing软件测试网X:A,|1x%d.}
'返回想设置的值51Testing软件测试网
A+Hy-RE&b
Function Set_TextAreaValue(textAreaBelongFrameId,textAreaValue)
c{!f"rbc
H)Zo^0 On error resume next
gvI
XSl,g*q0 ‘富文本框是在某个Frame框加下面的51Testing软件测试网+[ j}*qd&]?,?
If Browser("").page("").Frame("html id:="&textAreaBelongFrameId).Exist(0) then
4VO2WA]'{+q0 SetobjFrame=Browser("").page("").Frame("htmlid:="&textAreaBelongFrameId).Object51Testing软件测试网8?{i.P?
'获取Frame中所有的属性
:S7] ]v[.hu0 Set bjTextArea=objFrame.getElementsByTagName("BODY")
go/G5M%jY0‘因为在这个Frame下面只有一个Body,而这个Body刚好就是富文框设置内容的地方,所以我们只需要给innertext属性赋一个值即可。
R#Hy4u+~QA~0 objTextArea(0).InnerText=textAreaValue51Testing软件测试网?t:R
\8b ^rR;}r
Set_TextAreaValue=textAreaValue
LA V(f_(rm i0 end if51Testing软件测试网[j_l2t:H"z
B"{["Fk`
Yu;Y'o(S0 If err.Number<>0 Then
-^E4r;l
c{Nv"]S#w2r0 msgbox "出现异常"
|XI2a|z0 End If
y&fMn7Ig0sUSF0 Set bjFrame=nothing
?!\'bO,e
r0 Set bjTextArea=nothing
1rz5_Ti0p0 Set TextAreaCount=nothing
O%Du+csK],S'hj*WO,Q0 Set i=nothing51Testing软件测试网8^7Om7w7F6T+i
D8wGTv(CR
K0End Function51Testing软件测试网c'io6aW;Rw
51Testing软件测试网
gJHf1Ag/U
'获得富文本框的值,供查看时用51Testing软件测试网n1B5i
`.K,X9q5st3q;j
'textAreaBelongFrameId:富文本框所在objFrame中的ID
#T'a}6nH0'返回所获得的值
G{Wj r%F0 51Testing软件测试网.n(qB%?}7q D.j
Function Get_TextAreaValue(textAreaBelongFrameId)51Testing软件测试网 ACa!]2_5hl`
On error resume next51Testing软件测试网F
C/o8tS+B~*CW)e
If Browser("").page("title:=IBook后台管理").Frame("html id:="&textAreaBelongFrameId).Exist(0) then51Testing软件测试网5O\*xD9_
51Testing软件测试网?6y{z'[5Ce
Set bjFrame= Browser("").page("").Frame("html id:="&textAreaBelongFrameId).Object
aMIu7Rm0 '获取Frame中所有的属性51Testing软件测试网?~:N:\E-j(F-y
Set bjTextArea=objFrame.getElementsByTagName("BODY")
uo`!g6C1NY0X0 Get_TextAreaValue=objTextArea(0).InnerText51Testing软件测试网4a%g6Pj,H0Km0X&h
end if
^t9Erx-S0 If err.Number<>0 Then51Testing软件测试网$^U3^P(y_WVhl&P
msgbox "出现异常"51Testing软件测试网'K
fL@[$[wf
End If
bqgZ#Wt0 Set bjFrame=nothing
(Ddp mAN:T ~9f aM0 Set bjTextArea=nothing
1Mn/X1E"W0d`uzi0 Set TextAreaCount=nothing
6g&o~6|
fVt0 Set i=nothing
^%@a,|3i0End Function51Testing软件测试网.ie.q%r,Cx