在UFT中为web元素使用vbscript对象
现在,每当我想使用vbscript和uft与web元素交互时,我都会执行以下操作:在UFT中为web元素使用vbscript对象,vbscript,Vbscript,现在,每当我想使用vbscript和uft与web元素交互时,我都会执行以下操作: .WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']").something .WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']").something_else .WebButton("xpath:=//div[@id='controls']/bu
.WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']").something
.WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']").something_else
.WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']").another_thing
我可以用vbscript&uft来代替这种繁琐的方法吗
Object x = .WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']")
x.something
x.something_else
x.another_thing
这在vbscript中是否可行/容易?如果没有,那为什么呢?我意外地得到了答案。解决方案并不完全是我所期望的,但它接近我所需要的。我使用的是静态编程。我应该改用动态规划 动态描述性编程
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
'Descriptive object to identify Browser with a particular title
Set Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google"
'Descriptive object to identify Web page with a particular title
Set Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google"
'Descriptive object to identify a particular Web Button
Set Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in"
'Descriptive object to identify Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email"
'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync
' Enter Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set "qtpworld.com"
Dedit("name").value="Passwd"
'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set "qtp"
'Cick on the Sign In Button
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click
静态描述性编程:
'Username="qtpworld.com"
'Password="qtp"
'*****************************Login to gmail account using Static descriptive Programing ******************************
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
'Assign object property value to a variable pwd
pwd="Passwd"
'Wait till browser loads
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync
' Enter Email id in Username Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set "qtpworld.com"
'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=" & pwd).Set "qtp"
'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click
我偶然得到了一个答案。解决方案并不完全是我所期望的,但它接近我所需要的。我使用的是静态编程。我应该改用动态规划 动态描述性编程
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
'Descriptive object to identify Browser with a particular title
Set Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google"
'Descriptive object to identify Web page with a particular title
Set Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google"
'Descriptive object to identify a particular Web Button
Set Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in"
'Descriptive object to identify Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email"
'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync
' Enter Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set "qtpworld.com"
Dedit("name").value="Passwd"
'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set "qtp"
'Cick on the Sign In Button
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click
静态描述性编程:
'Username="qtpworld.com"
'Password="qtp"
'*****************************Login to gmail account using Static descriptive Programing ******************************
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
'Assign object property value to a variable pwd
pwd="Passwd"
'Wait till browser loads
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync
' Enter Email id in Username Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set "qtpworld.com"
'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=" & pwd).Set "qtp"
'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click