zoukankan      html  css  js  c++  java
  • QTP之有关富文本框赋值

    TIB工作室成员 文青山 作品

     

    前段时间在做QTP脚本时,遇到一个问题,主要问题是给富文本框赋值的问题。在录制时可以录制到给富文框赋值的过程,但是当回放时却放不了。通过SPY查看,富文本框的outerHtml发现,设置富文本框实际上是一个BODY,而不是Edit,所以回放时赋值是失败的。那么如何解决这个问题呢?最终通过操纵IE DOM结构来完成了这一过程。废话不说了,直接上代码(注意使用Object时不能回放于fireFox)

     

    '设置富文本框的值

    'bjtextAreaBelongFrameId:富文本框所在objFrame中的ID

    'textAreaValue:想在富文本框中所设置的值

    '返回想设置的值

    Function Set_TextAreaValue(textAreaBelongFrameId,textAreaValue)

                      On error resume next

                      ‘富文本框是在某个Frame框加下面的

                      If Browser("").page("").Frame("html id:="&textAreaBelongFrameId).Exist(0) then

                               SetobjFrame=Browser("").page("").Frame("htmlid:="&textAreaBelongFrameId).Object

                               '获取Frame中所有的属性

                               Set bjTextArea=objFrame.getElementsByTagName("BODY")

    因为在这个Frame下面只有一个Body,而这个Body刚好就是富文框设置内容的地方,所以我们只需要给innertext属性赋一个值即可。

                                        objTextArea(0).InnerText=textAreaValue

                                       Set_TextAreaValue=textAreaValue

                      end if

     

                      If err.Number<>0 Then

                               msgbox "出现异常"

                      End If

                      Set bjFrame=nothing

                      Set bjTextArea=nothing

                      Set TextAreaCount=nothing

                      Set i=nothing

     

    End Function

     

    '获得富文本框的值,供查看时用

    'textAreaBelongFrameId:富文本框所在objFrame中的ID

    '返回所获得的值

     

    Function Get_TextAreaValue(textAreaBelongFrameId)

                      On error resume next

                      If Browser("").page("title:=IBook后台管理").Frame("html id:="&textAreaBelongFrameId).Exist(0) then

     

                               Set bjFrame= Browser("").page("").Frame("html id:="&textAreaBelongFrameId).Object

                               '获取Frame中所有的属性

                               Set bjTextArea=objFrame.getElementsByTagName("BODY")

                                        Get_TextAreaValue=objTextArea(0).InnerText

                      end if

                      If err.Number<>0 Then

                               msgbox "出现异常"

                      End If

                      Set bjFrame=nothing

                      Set bjTextArea=nothing

                      Set TextAreaCount=nothing

                      Set i=nothing

    End Function

     

  • 相关阅读:
    Leetcode 532.数组中的K-diff数对
    Leetcode 529.扫雷游戏
    定增游戏(三)
    套利不归路(五)
    定增游戏(一)
    套利不归路(四)
    套利不归路(三)
    套利不归路(二)
    套利不归路(一)
    减持大逃亡(二)
  • 原文地址:https://www.cnblogs.com/testware/p/1996437.html
Copyright © 2011-2022 走看看