简体   繁体   中英

Using vbscript objects for web elements in UFT

Right now, every time I want to interact with a web element using vbscript & uft, I do this:

.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

Instead of this cumbersome way, can I do this with vbscript & uft:

Object x = .WebButton("xpath:=//div[@id='controls']/button[text()='Load Game']")
x.something
x.something_else
x.another_thing

Is this possible/easy in vbscript ? If not, then why ?

I accidentally got an answer here . The solution is not exactly what I was expecting, but it is close to what I need. I was using static programming. I should be using dynamic programming instead.

Dynamic descriptive programming

'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

Static descriptive programming:

'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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM