P. 1
QTP - getting current browser URL

QTP - getting current browser URL


|Views: 624|Likes:
Published by api-19840982

More info:

Published by: api-19840982 on Nov 30, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





QTP - getting current browser URL

I'm going to show and explain how to get current URL which is opened in a browser. For example, how to get URL "http://motevich.blogspot.com" from the following browser:

There are two solutions: 1. Using GetROProperty("URL") method (run-time object property) 2. Using "URL" property of "Object" (IE DOM Object) Let's consider both variants. 1. GetRoProperty("URL") method (run-time object property) GetRoProperty function reads properties of a run-time object in an application. If you open QTP Help on GetRoProperty function, you 'll see that this function can work with all objects:

So, for example:


o o o

to check whether a link is visible or not, use: Browser("bname").Page("pname").Link("lname").GetROPropert y("visible") to get a page's title, use: Browser("bname").Page("pname").GetROProperty("title") to check whether a window is maximized, use: Window("wname").GetROProperty("maximized") to get width of WebButton, use: Browser("bname").Page("pname").WebButton("btname").GetROP roperty("width")

Others properties are described in QTP Help. In our case, to get URL of the current WebPage, we will use: Browser("bname").Page("pname").GetRoProperty("URL") This is a sample QTP script:

(Click the image to enlarge it)

2. "URL" property of "Object" (IE DOM Object) The sample syntax is: Browser("bname").Page("pname").Object.URL What is "Object" in the above statement?

Actually, this is Internet Explorer Document Object Model (DOM) Object. You can read more about DOM here and here. Also, I recommend to read this interested article on working with IE DOM from Visual Basic. Tip: You can use DOM Object when running QTP test on Internet Explorer only! To make the long story short, I can say that using Object property you can get almost all elements and properties from Web page. Thus, I use URL property of Internet Explorer's DOM Object. All properties, collections, and methods of DOM Object are described in this MSDN article. Tip: The number of properties, accessed via DOM Object, is more bigger, than properties accessed via GetROProperty method. So, the result of above code is:

to enlarge it) Summary: Two ways were discussed: 1. GetROProperty("URL") (run-time object property) 2. "URL" property of "Object" (IE DOM Object)

(Click the image

GetROProperty method supports both IE & FireFox, but IE DOM Object provides more accessible properties and methods. Both can get URL of the current Web page.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->