For example, how to get URL "http://motevich.blogspot.com" from the following browser:
There are two solutions:
- Using GetROProperty("URL") method (run-time object property)
- Using "URL" property of "Object" (IE DOM Object)
- 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:- to check whether a link is visible or not, use:
Browser("bname").Page("pname").Link("lname").GetROProperty("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").GetROProperty("width")
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: - to check whether a link is visible or not, use:
- "URL" property of "Object" (IE DOM Object)
The sample syntax is:Browser("bname").Page("pname").Object.URLActually, this is Internet Explorer Document Object Model (DOM) Object.
What is "Object" in the above statement?
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:
Two ways were discussed:
- GetROProperty("URL") (run-time object property)
- "URL" property of "Object" (IE DOM Object)
Both can get URL of the current Web page.
Source