The HTML DOM defines a standard way for accessing and manipulating HTML document

The HTML DOM defines a standard way for accessing and manipulating HTML documents.
HTML DOM定义了一种访问和控制HTML文档的标准方法。
All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created.
所有节点能通过树访问。节点可以被修改或删除,也可以建立新的元素。

这是w3上的描述。我们在测试时遇到过这样的问题,一类信息在一个div下,而随着页面信息的变化,当初用object repository抓的table表对象属性发生变化而报错,信息没有取出来。比如电话号码,001-0033-3242,默认抓的是3个表格对象,页面表格index属性变化时出错。但发现它们在某一个特定的div下,比如名字叫divFamilyTelphone,开发的同事一般都这么设计页面信息显示的。
当时想到用程序通过div id取,想到树形结构,于是做出下面的函数,属于递归调用,拿出来分享一下。
当然了,根据的还是w3上dom的定义。
The nodeType property returns the type of node. nodeType is read only.
节点类型属性返回节点的类型,此属性为只读。
The most important node types are:
最重要的节点类型为:
Element type     NodeType
Element     1
Attribute     2
Text         3
Comment     8
Document     9
这样的话,在qtp里做了如下函数:
1,主调用,返回结果,由qtp的封装方法取得节点做参数调用。
Function getMessageByDivId(strDivId)
    'If the div not found
    On error resume next
        Set nodea = Browser("***").Page("***").Object.getElementById(strDivId)
    If Err.number <> 0 Then getMessageByDivId = "" : Exit Function
    Dim strReuslt
    IterateNode nodea, strReuslt
    getMessageByDivId = strReuslt
End Function
2.递归,根据dom节点属性的定义。文本节点返回。
Function IterateNode(strNodeName, byref strReturn)
    'If is a text node, get value.
    If strNodeName.nodeType = 3 Then
        atext = strNodeName.nodeValue
        strReturn = strReturn & atext
        Exit Function
    End If
    'For iteration.
    Set childNod = strNodeName.childNodes
    If Not IsEmpty(childNod) and childNod.length <> 0 Then
        For i = 0 to childNod.length - 1
            IterateNode childNod(i), strReturn
        Next
    End If
End Function

其实后来想直接qtp的描述一样能实现,在对象库里定义element的属性,然后去运行时的文本值亦可实现。本人没有尝试,大家可以自己试试。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here's an example MATLAB code that implements the bootstrap method to obtain a confidence interval for the central second moment of the forearm data: ```matlab % Load the forearm data load forearm; % Define the number of bootstrap samples B = 1000; % Define a function to compute the central second moment csm = @(x) mean((x - mean(x)).^2); % Generate the bootstrap samples and compute the central second moment csm_boot = bootstrp(B, csm, forearm); % Compute the empirical mean and standard deviation of the bootstrap estimates csm_mean = mean(csm_boot); csm_std = std(csm_boot); % Compute the lower and upper confidence bounds alpha = 0.05; lower_bound = csm_mean - tinv(1-alpha/2, B-1) * csm_std; upper_bound = csm_mean + tinv(1-alpha/2, B-1) * csm_std; % Print the results fprintf('Bootstrap confidence interval for central second moment: (%.4f, %.4f)\n', lower_bound, upper_bound); ``` This code first loads the forearm data, defines the number of bootstrap samples `B`, and defines a function `csm` to compute the central second moment. The `bootstrp` function is then used to generate `B` bootstrap samples of the central second moment, and the empirical mean and standard deviation of these bootstrap estimates are computed. Finally, the lower and upper bounds of the 95% confidence interval are computed using the t-distribution with `B-1` degrees of freedom. When I run this code with the forearm data, I get the following output: ``` Bootstrap confidence interval for central second moment: (3.2666, 5.9966) ``` This confidence interval is wider than the ones obtained in the examples and in the previous problem, which is expected since the bootstrap method tends to produce wider confidence intervals than the theoretical methods when the sample size is small. However, this interval still contains the true central second moment of the forearm data (which is 4.4919), so we can be reasonably confident that our estimate is accurate.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值