Search code examples
vbscriptqtphp-uft

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.


Solution

  • 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