51Testing软件测试网hz%o!r lzsJ%F
I2~vXVDt@(Y%v-G0
DOM介绍
9}9v_'X7t%am0
常用对象51Testing软件测试网2i5}:Oh7hBT
document对象:文档中所有对象
#HfYe4m0
Body对象:文档中body部分的对象
x}5n4Yuj6e[`0
查找对象常用的方法:51Testing软件测试网8|\:~N*eE
a:PA
getElementbyid() 返回对象拥有指定id的第一个对象 html标记的id属性
4Ql p-Fold0
getElementsbyName() 返回带有指定名称的对象的集合 name属性51Testing软件测试网(qO2R\,lt~
getElementsbyTagName() 返回带有指定标签名的对象的集合 html标记51Testing软件测试网#b"R%q#vve/H
也可以用集合来查找对象
v+p
MJ&es0
如options代表下拉框元素的集合
Q9p4W F#WCR:U9DG*]0
elements代表表单中所有的元素51Testing软件测试网(^"hw6v(I#U4YxNM
如访问某个下拉框的选项51Testing软件测试网| Pzlf
[L8Tc
set sel=ie.document.getelementbyid("**").options
T,n7I{8uA,^3t0
for each opt in sel
2];M1[%A"J5X+D:p{0
if opt.text="*" then51Testing软件测试网9Uli5E+ko3x(o;e*rkW0c
opt.selected=true
H3H"h8N
J0R0
end if51Testing软件测试网)@s@8EZx(g i*Q
next
T
PFwD3~!~C0
X$zg+]3hRH*[Rc0
有的下拉框每个选项是有optionid的,可以这样访问51Testing软件测试网'X(r%Su$A.n+kd
ie.document.getelementbyid("**").selected=true
)M}K m:w,Q0AVO*D3Ce/e0
i:E([+R$TE
W0
一个例子,访问某网页,检查密码为空的提示是否正确51Testing软件测试网 |RUWF6I5Z;I
DIM URL=""
`gQ2OD \0
set ie=createobject("internetexplorer.application")
c?!||3BV}0
ie.visiable=true51Testing软件测试网z
\PJ2c6l7z'P8}
ie.navigate URL
FBxLed+oC0
wscript.sleep 2000
m O ZPr0
ie.document.getelementsbytagname("input")(1).value="usename"51Testing软件测试网 Qo]9?5P;YVR
ie.document.getelementsbytagname("input")(2).value=""
Oc$R)I.hSt0
ie.document.getelementsbytagname("button")(0).click51Testing软件测试网 o(Ak!M-n@
wscript.sleep 2000
DP+\-e'Tq*Cn4rd|
S0
if ie.document.getelementsbyid("errordiv").innertext="密码不能为空" then msgbox “提示正确”
'rH
~H~!_0
2D.f:w8jXW_ qm!Y0
else
_,zY:V R5gd~0
……
b7M V|;j0
end if51Testing软件测试网3U/hD
k$|#wY\