简体   繁体   中英

QTP/UFT - Store Browser().Page() as Variable

Is it possible to take this line of code:

Code:

Browser("site").Page("site").WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight

And do something like this:

Code:

WebLink = Browser("site").Page("site")

WebLink.WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight

I think in terms of readability where you have a TON of code, this would read much better. You only have to declare this once and call the variable.

Unless there is a better way I just haven't thought of.

I actually found a link explaining how to solve my scenario shortly after posting the question, but decided to leave it open simply for the way the question is phrased for future newbies..

Link:

Buildup and reference of objects in HP UFT

This lead me to the below solution:

Code:

Set WebLink = Browser("site").Page("site")

WebLink.WebElement("xpath:= ((//*[contains(text(), 'Login')]))[1]").HighLight

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