簡體   English   中英

在UFT中為web元素使用vbscript對象

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM