VBS+DOM实现IE自动化操作

上一篇 / 下一篇  2012-11-01 22:44:13 / 个人分类:VBScript

 51Testing软件测试网7KTvson"@ F-o~G

 

/W8FTZ S\XV0

DOM介绍

Xi#E$o$x-B;N1}0

常用对象51Testing软件测试网b8}uT3[x6x*l

document对象:文档中所有对象

Y6EYSV[0

Body对象:文档中body部分的对象51Testing软件测试网4u P1^R|E(b

查找对象常用的方法:51Testing软件测试网3H1Uh2ZfogF;Ih,P

getElementbyid() 返回对象拥有指定id的第一个对象  html标记的id属性51Testing软件测试网/u:`}1UJ*U

getElementsbyName() 返回带有指定名称的对象的集合   name属性51Testing软件测试网'b?gCBx(E,~ a4Rj

getElementsbyTagName() 返回带有指定标签名的对象的集合  html标记51Testing软件测试网o{yG iR-}|

也可以用集合来查找对象51Testing软件测试网8} |kr dL

如options代表下拉框元素的集合

C5t,GF0v;~q![~0

elements代表表单中所有的元素51Testing软件测试网O^5g&nJ6Fq:a ~7`

如访问某个下拉框的选项51Testing软件测试网)Y!FDb5i

set sel=ie.document.getelementbyid("**").options51Testing软件测试网]zt*Kex OA&CI

for each opt in sel51Testing软件测试网 d$l@0kW%ma

if opt.text="*" then

4T&\8Q@i$c0

opt.selected=true51Testing软件测试网Xf pT9Q8|X

end if51Testing软件测试网!O3k+pa,S

next

.O G b3d\0

 

:D:m'[&RacT I0

有的下拉框每个选项是有optionid的,可以这样访问

4]/F,WOXq3^0

ie.document.getelementbyid("**").selected=true

/x$O)~ez0

 51Testing软件测试网{Y9TZgf3W)T

一个例子,访问某网页,检查密码为空的提示是否正确

)w ~;V Hq"W;^7r0

DIM URL=""51Testing软件测试网C+b)b{K4P8f

set ie=createobject("internetexplorer.application")

7Z}NK*G1Y*C0

ie.visiable=true

8D!j,PkC S0

ie.navigate URL51Testing软件测试网.jx b M.^y:j?(f-Z9Yx

wscript.sleep 2000

r(v `8X]u/O Z7Y9Y0

ie.document.getelementsbytagname("input")(1).value="usename"51Testing软件测试网1{zT{ R$Cj

ie.document.getelementsbytagname("input")(2).value=""

7t.S8FVj-^0

ie.document.getelementsbytagname("button")(0).click

/P[7v;hL0W3_*M7[0

wscript.sleep 2000

3w(i:rnrIa+V0

if ie.document.getelementsbyid("errordiv").innertext="密码不能为空" then msgbox 提示正确

"Y%t9Pm3?i f&o9Us0

 

L z&OZ1N;?DO0

else

Y6hOE]4Fd5z0

……51Testing软件测试网~n3u#C,@

end if

&E T}h-g0

TAG:

 

评分:0

我来说两句

Open Toolbar