![](/img/trans.png)
[英]Unable to access button in different frame in a web page using vbscript in uft
[英]Using vbscript objects for web elements in UFT
现在,每次我想使用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']/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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.