51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 6887|回复: 20
打印 上一主题 下一主题

[原创] 如何给WebCheckBox的属性赋值

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-1-18 11:34:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
需求:

如下图中,角色名称是会不断增加的,所以我想先判断“地区管理总部”在第几行,然后在“地区管理总部”前的webcheckbox打勾

[ 本帖最后由 xihong2004 于 2008-1-18 11:38 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2008-1-18 11:42:02 | 只看该作者
解决方法:

‘遍历表格上的所有值,与"地区管理总部"对照’,得出"地区管理总部"所在的行号,并把行号转为字符型

var_RowCount = Browser("新意新一代证券综合管理平台E-SIM6.0").Page("新意新一代证券综合管理平台E-SIM6.0_2").Frame("frmbody").WebTable("选择").RowCount()
var_GetCellData = Browser("新意新一代证券综合管理平台E-SIM6.0").Page("新意新一代证券综合管理平台E-SIM6.0_2").Frame("frmbody").WebTable("选择").GetCellData(var_RowCount,3)
While not var_GetCellData="地区管理总部"
        var_RowCount = var_RowCount -1
        var_GetCellData = Browser("新意新一代证券综合管理平台E-SIM6.0").Page("新意新一代证券综合管理平台E-SIM6.0_2").Frame("frmbody").WebTable("选择").GetCellData(var_RowCount , 3)
bmjsmc_index = cstr (var_RowCount)

‘然后把bmjsmc_index,赋值到webcheckbox的属性值中’

[ 本帖最后由 xihong2004 于 2008-1-18 11:44 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
回复 支持 反对

使用道具 举报

  • TA的每日心情
    开心
    2016-8-25 10:16
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    3#
    发表于 2008-1-18 11:44:28 | 只看该作者
    谢谢了
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
     楼主| 发表于 2008-1-18 11:46:03 | 只看该作者
    问题:

    QTP执行时无法取到bmjsmc_index,不会在相应的webcheckbox中打勾
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
    发表于 2008-1-18 12:23:40 | 只看该作者
    QuickTest Professional identifies WebCheckBox objects using an index value. The checkbox the user needs to select may appear in different positions on the page. Is there a way to select the checkbox using its adjacent text?



    Solution



    Use the custom WebCheckBoxByLabel function (Internet Explorer only)
    Note:
    This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury Customer Support. You are responsible for any and all modifications that may be required.

    WebCheckBoxByLabel( parent, arg )
    parent        The Page object containing the checkbox item you want to select
    arg        The text to locate


    This function uses the DOM object, so it will only work on Internet Explorer.

    Function WebCheckBoxByLabel( parent, arg )

        ' Create a description for the WebCheckBox object
        Set desc = Description.Create()
        desc("type").Value = "checkbox"
        desc("html tag").Value = "INPUT"

        ' Retrieve all WebCheckBox objects on the page
        Set cbcol = parent.ChildObjects(desc)

        cnt = cbcol.count
        ' Loop through the WebCheckBox objects
        For obj = 0 to cnt-1
            ' Get the text next to the checkbox
            text = cbcol(obj).object.getAdjacentText("afterend")
            ' Is this the text we're looking for?
            If arg = Trim(text) Then
                cbcol(obj).Set "ON"
                Exit For
            End If
        Next

    End Function

    RegisterUserFunc "Page", "WebCheckBoxByLabel", "WebCheckBoxByLabel"

    Example:
    Browser("Browser").Navigate "http://support.mercury.com"
    Browser("Browser").Sync
    Browser("Browser").Page("Page").WebCheckBoxByLabel "Remember me"


    The above method sets the first instance of the WebCheckBox with the specified text that is found on the page. If you need to specify the instance, the function will need to be modified.

    If the WebCheckBox objects are contained within a WebTable object, you can also refer to the following articles:
    Document ID 21805 - How to select checkbox in the WebTable by the content next to it
    Document ID 27498 - How to select a checkbox in an HTML table based on a value in another column
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    6#
    发表于 2008-1-18 12:25:47 | 只看该作者
    Use the custom user-defined function WebTableSelectCheckbox
    To locate a row in a WebTable based on the content of a specified cell, use the GetRowWithCellText method. For inforamation on GetRowWithCellText, refer to Document ID 47222 - How to find a row in a WebTable using the text of a specified cell.
    To select a checkbox in a WebTable based on text near it, you can also use the custom WebTableSelectCheckbox function.
    Note:
    This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury Technical Support. You are responsible for any and all modifications that may be required.
    The WebTableSelectCheckbox function will search through a Web (HTML) table, locate the item being searched for, and select the item's corresponding checkbox.
    WebTableSelectCheckbox (WebTblObj, ItemToLocate, ItemColumn, ChkBoxCol)
    WebTblObj        The table object which is created before executing the subprocedure.
    ItemToLocate        The item in the Web table to locate.
    ItemColumn        The column number that needs to be searched.
    ChkBoxCol        The column number that contains the checkboxes.
    Sub WebTableSelectCheckbox (WebTblObj, ItemToLocate, ItemColumn, ChkBoxCol)
       ' Total number of rows in html_table
       TotalRows = WebTblObj.RowCount
       ' Remain in loop until all rows are searched or until the item is found.
       For row= 3 To TotalRows
          ' Retrieve the item from the specified column
          ValueShown = WebTblObj.GetCellData(row,ItemColumn)
          ' If item retrieved matches the item searching for, set the
          '  checkbox located in the specified column, and exit the for loop.
          If (ItemToLocate = Trim(ValueShown)) Then
             Set ChkBoxObj = WebTblObj.ChildItem(row, ChkBoxCol,"WebCheckBox", 0)
             ChkBoxObj.Set "ON"
             Exit For
          End If
       Next
    End Sub

    Example:
    ' Corresponding column numbers for each column
    colSELECT = 1
    colNAME = 2
    colEMPID = 3
    colJOBTITLE = 4
    colDEPARTMENT = 5
    ' Create an object for the Web table, this object will be passed into the sub procedure.
    Set MyObj = Browser("Multiple Oper").Page("Multiple Oper").WebTable("Direct Reports")
    ' Locate the "323214" object in the colEMPID column and set the checkbox in the first column.
    WebTableSelectCheckbox MyObj, "323214", colEMPID, 1
    Note:
    You can also register the function so it can be used directly with the WebTable object. For information on registering custom functions for use with test objects, refer to Document ID 25943 - How to register a user-defined function for use with objects
    Example:
    RegisterUserFunc "WebTable", "WebTableSelectCheckbox", "WebTableSelectCheckbox"
    Browser("Multiple Oper").Page("Multiple Oper").WebTable("Direct Reports").WebTableSelectCheckbox "323214", colEMPID, 1

    Another solution would be to use the .Object method to access the DOM to find and select the object.
    Note:
    This suggestion is supported only in Internet Explorer.
    1. Use the DOM to locate and get a reference to the row with the text you want. You can use descriptive programming to find the TR element with an "innertext" value containing your needed text.
    For more information on accessing the DOM and using the .Object property, please refer to the following articles:
    Document ID 13590 - How to access all the objects in a webpage (Internet Explorer)
    Document ID 21834 - How to access an object's methods and properties
    2. Get a collection of the checkbox objects in that row.
    3. Loop through the collection to set the checkbox.
    Example:
    The following code clicks the checkbox next to the word "Rachel" in the table in the attached HTML file:
    ' find the table row that contains the text we are looking for
    Set row = Browser("Friends").Page("Friends").WebTable("Favorite Friends:").WebElement("html tag:=TR","innertext:=.*Rachel.*").Object
    ' get all the objects in the row that have an INPUT tag
    Set CheckBoxes = row.getElementsByTagName("INPUT")
    ' click on the checkboxes
    For Each obj In CheckBoxes
        ' Once found, click the checkbox...
       If (obj.type="checkbox") Then
          obj.click
       End If
    Next
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    7#
    发表于 2008-1-18 12:27:26 | 只看该作者
    Use the custom user-defined function WebTableSelectCheckbox
    To locate a row in a WebTable based on the content of a specified cell, use the GetRowWithCellText method. For inforamation on GetRowWithCellText, refer to Document ID 47222 - How to find a row in a WebTable using the text of a specified cell.
    To select a checkbox in a WebTable based on text near it, you can also use the custom WebTableSelectCheckbox function.
    Note:
    This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Mercury Technical Support. You are responsible for any and all modifications that may be required.
    The WebTableSelectCheckbox function will search through a Web (HTML) table, locate the item being searched for, and select the item's corresponding checkbox.
    WebTableSelectCheckbox (WebTblObj, ItemToLocate, ItemColumn, ChkBoxCol)
    WebTblObj        The table object which is created before executing the subprocedure.
    ItemToLocate        The item in the Web table to locate.
    ItemColumn        The column number that needs to be searched.
    ChkBoxCol        The column number that contains the checkboxes.
    Sub WebTableSelectCheckbox (WebTblObj, ItemToLocate, ItemColumn, ChkBoxCol)
       ' Total number of rows in html_table
       TotalRows = WebTblObj.RowCount
       ' Remain in loop until all rows are searched or until the item is found.
       For row= 3 To TotalRows
          ' Retrieve the item from the specified column
          ValueShown = WebTblObj.GetCellData(row,ItemColumn)
          ' If item retrieved matches the item searching for, set the
          '  checkbox located in the specified column, and exit the for loop.
          If (ItemToLocate = Trim(ValueShown)) Then
             Set ChkBoxObj = WebTblObj.ChildItem(row, ChkBoxCol,"WebCheckBox", 0)
             ChkBoxObj.Set "ON"
             Exit For
          End If
       Next
    End Sub

    Example:
    ' Corresponding column numbers for each column
    colSELECT = 1
    colNAME = 2
    colEMPID = 3
    colJOBTITLE = 4
    colDEPARTMENT = 5
    ' Create an object for the Web table, this object will be passed into the sub procedure.
    Set MyObj = Browser("Multiple Oper").Page("Multiple Oper").WebTable("Direct Reports")
    ' Locate the "323214" object in the colEMPID column and set the checkbox in the first column.
    WebTableSelectCheckbox MyObj, "323214", colEMPID, 1
    Note:
    You can also register the function so it can be used directly with the WebTable object. For information on registering custom functions for use with test objects, refer to Document ID 25943 - How to register a user-defined function for use with objects
    Example:
    RegisterUserFunc "WebTable", "WebTableSelectCheckbox", "WebTableSelectCheckbox"
    Browser("Multiple Oper").Page("Multiple Oper").WebTable("Direct Reports").WebTableSelectCheckbox "323214", colEMPID, 1

    Another solution would be to use the .Object method to access the DOM to find and select the object.
    Note:
    This suggestion is supported only in Internet Explorer.
    1. Use the DOM to locate and get a reference to the row with the text you want. You can use descriptive programming to find the TR element with an "innertext" value containing your needed text.
    For more information on accessing the DOM and using the .Object property, please refer to the following articles:
    Document ID 13590 - How to access all the objects in a webpage (Internet Explorer)
    Document ID 21834 - How to access an object's methods and properties
    2. Get a collection of the checkbox objects in that row.
    3. Loop through the collection to set the checkbox.
    Example:
    The following code clicks the checkbox next to the word "Rachel" in the table in the attached HTML file:
    ' find the table row that contains the text we are looking for
    Set row = Browser("Friends").Page("Friends").WebTable("Favorite Friends:").WebElement("html tag:=TR","innertext:=.*Rachel.*").Object
    ' get all the objects in the row that have an INPUT tag
    Set CheckBoxes = row.getElementsByTagName("INPUT")
    ' click on the checkboxes
    For Each obj In CheckBoxes
        ' Once found, click the checkbox...
       If (obj.type="checkbox") Then
          obj.click
       End If
    Next
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    8#
    发表于 2008-1-18 15:24:48 | 只看该作者
    晕了
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    9#
     楼主| 发表于 2008-1-18 16:05:57 | 只看该作者
    狂晕了
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    10#
    发表于 2008-1-18 17:05:32 | 只看该作者
    以上是对webcheckbox进行处理的三种方法。代码很简单,就是英文而已,为什么要晕呢?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    11#
    发表于 2008-1-18 18:28:47 | 只看该作者
    我的建议:
            用webtable的方法获得地区管理总部的行,这样这个webcheckbox的行列都固定了。我觉得这个方法最简单。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    12#
    发表于 2008-1-18 18:30:05 | 只看该作者
    具体的webtable的函数自己查一下帮助好了,都有的。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    13#
     楼主| 发表于 2008-1-21 10:38:21 | 只看该作者
    原帖由 frankwangzy1103 于 2008-1-18 18:28 发表
    我的建议:
            用webtable的方法获得地区管理总部的行,这样这个webcheckbox的行列都固定了。我觉得这个方法最简单。


    我已经取到了地区管理总部的行,并把这个行号赋到了webcheckbox的index属性中了,问题是现在QTP不会选中这个webcheckbox,也就是说这个行号赋得有问题
    另外说明一下,webcheckbox的行号是不固定的

    谢谢大家的帮忙!
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    14#
    发表于 2008-1-22 17:50:07 | 只看该作者
    哇...顶阿...偶也正好遇到这样的问题呢 求救呢哇...
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    15#
    发表于 2008-1-23 11:33:45 | 只看该作者
    原帖由 xihong2004 于 2008-1-21 10:38 发表


    我已经取到了地区管理总部的行,并把这个行号赋到了webcheckbox的index属性中了,问题是现在QTP不会选中这个webcheckbox,也就是说这个行号赋得有问题
    另外说明一下,webcheckbox的行号是不固定的

    谢谢大家的 ...

    你确定这个webcheckbox的行号就是它的index吗?我的方法:
    set obj = Browser().Page().Webtable().ChildItem (Row, Column, "WebCheckBox", Index)
    obj.set "on"
    你这样试试行吗?
    还有行号不固定没关系啊,可以每次调用的时候get这个行号就行了,只要它的innertext"地区管理总部"存在就能得到的。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    16#
    发表于 2008-1-23 13:06:30 | 只看该作者
    不是吧...楼主现在的问题是qtp录制不了勾选webcheckbox的问题阿,也就是说对象库里也不存在这个对象阿..
    我也想过楼上的办法,但不知道webtable括号里面的值怎么取得阿?到哪里取找哇....
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    17#
    发表于 2008-1-23 13:25:05 | 只看该作者
    原帖由 flyingkite 于 2008-1-23 13:06 发表
    不是吧...楼主现在的问题是qtp录制不了勾选webcheckbox的问题阿,也就是说对象库里也不存在这个对象阿..
    我也想过楼上的办法,但不知道webtable括号里面的值怎么取得阿?到哪里取找哇....

    Webtable很好确定的,你用spy随便点一个webtable里面的对象,他的上面的节点里面就有webtable的,因为我看到他的截图是一个table。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    18#
    发表于 2008-1-23 18:03:44 | 只看该作者
    我用了你的方法
    set obj = Browser().Page().Webtable().ChildItem (Row, Column, "WebCheckBox", Index)
    obj.set "on"
    报错了
    object requirede
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    19#
     楼主| 发表于 2009-8-5 16:17:47 | 只看该作者
    用描述编程搞定了
    webcheckbox(index:=行号).set "ON"
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2021-6-9 14:08
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    20#
    发表于 2012-10-16 21:11:48 | 只看该作者
    研究下webtable()方法
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-11-23 18:25 , Processed in 0.084828 second(s), 29 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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