Monday, April 4, 2011

How to get Text of statusbar from the QTP

When you work in QTP with Web applications, it is sometimes necessary to get a text of browser's status bar.
Let's see for example the following browser:



There are two ways:
1.Object.StatusText property of Browser object
2.GetROProperty("text") method of WinStatusBar object
1.Getting text of Status Bar using Object.StatusText property of Browser object

To access text of Status Bar, we use Browser's Object object and its StatusText property.
Browser("bname").Object is a reference to the Internet Explorer's DOM object. To be more precise, it's a reference to the Internet Explorer's IWebBrowser2 interface.

Using Browser("bname").Object, you can access different methods and properties of IE, for example:
#
Statement
Meaning
1
Browser("bname").Object.GoBack
Navigates backward one item in the history list
2
Browser("bname").Object.LocationURL
Gets the URL of the page that is currently displayed
3
Browser("bname").Object.StatusText
Sets or gets the text in the status bar for the object
4
Browser("bname").Object.ToolBar
Sets or gets whether toolbars for the object are visible

So, our code is simpe enough:

sText = Browser("QTP - How to get Status").Object.StatusText
MsgBox sText

And its result is:



Note: Since we use Internet Explorer's IWebBrowser2 interface, we can use this solution win IE only. It doesn't work with FireFox. The next solution will be compatibe with both IE and FF.

1.Getting text of Status Bar using GetROProperty("text") method of WinStatusBar object

Status bar is a part of browser's window. There is a special class to handle it from QTP - WinStatusBar. We can get text of WinStatusBar using GetROProperty("text") method.

So, I add Status Bar to QTP's Object Repository (OR):



The final script is:

sText = Browser("QTP - How to get Status").WinStatusBar("msctls_statusbar32").GetROProperty("text")
MsgBox sText

And its result is:



Note: This solution works correctly both for IE and FF, but it requires additional operations with Object Repository.

No comments: