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

     

  • 相关阅读:
    2021.07.11 【ABAP随笔】采购订单Message输出打印
    项目管理43210学习笔记
    Rails跳过回调方法
    树莓派接USB温湿度传感器(python)
    Visual Studio2019安装时报错Microsoft.Net.4.7.2.FullRedist的解决方法
    微信浏览器中H5使用wx-open-launch-app打开第三方APP
    Linux系统使用qq邮箱在线发送邮件
    LRU工程实现源码(一):Redis 内存淘汰策略
    Android Studio解决Build Log出现乱码问题
    git新拉取项目
  • 原文地址:https://www.cnblogs.com/testware/p/1996437.html
Copyright © 2011-2022 走看看