Browser Object
Description
A Web browser (or browser tab).
IMPORTANT
The name of the Browser test object is the same as the name of the first Page test object that is learned in that browser or tab.
Although by default, the Browser test object has only the CreationTime property in its description, you can add properties to the description to enhance proper Browser identification. For example, the HasToolbar description properties (True/False) can be used to help filter out popup advertisement browser windows, which do not normally have toolbars, and the OpenedByTestingTool description properties (True/False) can help to identify the specific browser(s) that UFT One opened. You can add these description properties to the default browser object definitions in the Object Identification dialog box or to a specific browser object in the Object Properties dialog box or the Object Repository window.
Note: When working with an XBAP application, the Navigate and Learn function does not learn SWF objects in a Browser window. Learning all objects in the Browser window of an XBAP application only learns the Web objects. You can learn WPF objects by starting to the Navigate and Learn function from the WpfWindow object. For details, see the WpfWindow object.
Operations
The sections below list the built-in methods and properties that you can use as operations for the Browser object.
Note: You can also view a list and descriptions of the Browser description properties, for use in object repository descriptions, programmatic descriptions, checkpoint and output value steps, and as argument values for the GetTOProperty and GetROProperty methods.
Methods
Back | Navigates to the previous page in the browser history list. |
CaptureBitmap | Saves a screen capture of the object as a .png or .bmp image using the specified file name. |
Check | Checks whether the actual value of an item matches the expected value. |
CheckProperty | Checks whether the actual value of the specified object property matches the specified expected value within the specified timeout. |
ChildObjects | Returns the collection of child objects contained within the object. |
GetAllROProperties | Returns the collection of properties and current values from the object in the application. |
ClearCache | Clears the browser cache. |
Close | Closes the browser window (or tab) that this test object represents. |
CloseAllTabs | Closes all tabs (if any) and closes the browser window. |
DeleteCookies | Deletes cookies from the browser. |
DialogExists | Checks if a browser dialog box (such as alert, confirmation, or prompt) is currently open. |
EmbedScript | Runs the specified JavaScript each time a page or frame loads or refreshes in the browser. |
EmbedScriptFromFile | Runs the JavaScript stored in the specified file each time a page or frame loads or refreshes in the browser. |
Forward | Navigates to the next page in the browser history list. |
FullScreen | Sets the browser's full-screen mode off or on or toggles it. |
GetDialogText | Retrieves the text displayed in a browser dialog box such as alert, confirmation, or prompt. |
GetROProperty | Returns the current value of the description property from the object in the application. |
GetTOProperties | Returns the collection of properties and values used to identify the object. |
GetTOProperty | Returns the value of the specified description property from the test object description. |
Highlight | Highlights the object in the application. |
HandleDialog | Clicks a button on the browser dialog box (alert, confirmation, or prompt) after entering a value if necessary. |
Home | Navigates to the home page configured in the browser's settings. |
IsSiblingTab | Indicates whether the specified tab is a sibling of this tab object in the same browser window. |
Maximizes the browser window. | |
Minimize | Minimizes the browser window to an icon. |
Navigate | Opens a specified URL in the browser. |
OpenNewTab | Opens a new tab in the browser window. |
Output | Retrieves the current value of an item and stores it in a specified location. |
Quit | Closes all active browser tabs and windows, and kills any browser-related processes. |
Refresh | Refreshes the current page. |
RefreshObject | Instructs UFT One to re-identify the object in the application the next time a step refers to this object. |
Restore | Restores the browser window to its previous size. |
SetTOProperty | Sets the value of the specified description property in the test object description. |
Sync | Waits for the browser to complete the current navigation. |
ToString | Returns a string that represents the test object. |
WaitProperty | Waits until the specified object property achieves the specified value or exceeds the specified timeout before continuing to the next step. |
Properties
Exist | Checks whether the object currently exists in the open application. |
Object | Accesses the native methods and properties of the object. |
Back Method
Description
Navigates to the previous page in the browser history list.
Syntax
object.Back
Return Type
None
IMPORTANT
This method is identical to clicking the browser's Back button.
Example
'The following example uses the Back method to return to the previous page in the browser. SystemUtil.Run "iexplore.exe", "http://www.google.com" Browser("Google").Page("Google").Sync Browser("Google").Navigate "http://www.cnn.com" Browser("Google").Page("CNN.com - Breaking News,").Sync Wait 10 ' we can read the latest news Browser("Google").Back Browser("Google").Page("Google").Sync Browser("Google").Navigate "http://www.Yahoo.com" Browser("Google").Page("Yahoo!").Sync 'The ReadMail function reads all new mail from the specific mail box ReadMail ("John@yahoo.com")
ClearCache Method
Description
Clears the browser cache.
Syntax
object.ClearCache
Return Type
None
IMPORTANT
This method does not delete the browser's cookies. To do so, use the DeleteCookies method.
Example
'The following example uses the ClearCache method to clear the cache from the browser, 'and then uses the Refresh method to refresh the objects in the browser. Browser("Mercury Tours").ClearCache Browser("Mercury Tours").Refresh
Close Method
Description
Closes the browser window (or tab) that this test object represents.
Syntax
object.Close
Return Type
None
IMPORTANT
Use the CloseAllTabs method to close the currently open tab, all sibling tabs, and the parent browser window.
Example
'The following example uses the Close method to close the 'Mercury Tours application. Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20 Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5 Browser("Mercury Tours").Close
CloseAllTabs Method
Description
Closes all tabs (if any) and closes the browser window.
Syntax
object.CloseAllTabs
Return Type
None
IMPORTANT
- This method closes all of the following:
- the tab that is currently open
- all sibling tabs in the parent browser window
- the parent browser window
Use the Close method to close only the tab (and the browser if the browser contains one or no tabs).
- This method is not recorded on Chrome browsers.
Example
'The following example uses the CloseAllTabs method to close all the tabs 'in a Web browser. Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20 Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5 'Open another tab in the browser Browser("Mercury Tours").OpenNewTab 'Perform an operation on the second tab Browser("Google Browser").Page("Google").WebEdit("q").Set "Hello World" 'Close both tabs Browser("Mercury Tours").CloseAllTabs 'or you can use the following line as well 'Browser("Google Browser").CloseAllTabs
DeleteCookies Method
Description
Deletes cookies from the browser.
Syntax
object.DeleteCookies [FromSource]
Arguments
Parameter | Description |
---|---|
FromSource |
Optional. A String value. The full or partial domain of the source. For example, entering MySite.com or MySite.net clears cookies only from the specified site, and entering MySite clears cookies from all related domains. Default value = "" |
Return Type
None
IMPORTANT
This method does not clear the browser's cache. To do so, use the ClearCache method.
This method is not supported on Safari browsers.
Example
'The following example uses the DeleteCookies method to clear previously stored data in the specified browser. 'Search for a product in an online shopping site Browser("MyShoppingSite.com:").Navigate "www.MyShoppingSite.com" Browser("MyShoppingSite.com:").Page("MyShoppingSite.com: Online Shopping").WebEdit("field-keywords").Set "Unified Functional Testing" Browser("MyShoppingSite.com:").Page("MyShoppingSite.com: Online Shopping").Image("Go").Click 'Add the product to the shopping cart Browser("MyShoppingSite.com:").Page("MyShoppingSite.com: Unified Functional Testing").Link("Unified Functional Testing").Click Browser("MyShoppingSite.com:").Page("MyShoppingSite.com: Unified Functional Testing").Image("Add to Shopping Cart").Click 49, 10 Browser("MyShoppingSite.com:").Page("MyShoppingSite.com Shopping Cart").Image("Add to cart").Click Browser("MyShoppingSite.com:").Page("MyShoppingSite.com Shopping Cart_2").Link("Cart").Click 'Delete cookies from the shopping site domain and refresh the browser Browser("MyShoppingSite.com:").DeleteCookies "MyShoppingSite" Browser("MyShoppingSite.com:").Refresh
DialogExists Method
Description
Checks if a browser dialog box (such as alert, confirmation, or prompt) is currently open.
Syntax
object.DialogExists
Return Type
A Boolean value.
IMPORTANT
This method is supported on Google Chrome versions 26 and higher.
Example
'The following example uses the DialogExists method to verify whether a browser dialog box '(such as an alert, confirmation, or prompt) exists. If the dialog box does exist, it uses 'the GetDialogText method to retrieve the message displayed, and then it uses the HandleDialog 'method to click the OK button and close the dialog box. If Browser(“B”).DialogExists then Print Browser(“B”).GetDialogText Browser(“B”).HandleDialog End If
EmbedScript Method
Description
Runs the specified JavaScript each time a page or frame loads or refreshes in the browser.
Syntax
object.EmbedScript Script
Arguments
Parameter | Description |
---|---|
Script |
Required. A String value. The full content of the JavaScript to embed. |
Return Type
None
IMPORTANT
- The script remains embedded until you close the browser, or until the run session ends.
- Using this method to perform alert operations may result in unexpected behavior.
- The entire script must be specified as the argument value (as a string or variable). To embed a JavaScript file, use the EmbedScriptFromFile method.
- To run this method, the security settings in your Web browser must be set to allow active scripting. Otherwise, steps using this method will fail.
Example
The following example uses the EmbedScript method to embed a JavaScript function in the browser.
Sub EmbedScript_Example() 'Embed the JavaScript script Browser("MySearchEngine").EmbedScript"function(){newDiv = document.createElement('div'); newDiv.innerHTML = '<h1>EmbedScript Test</h1>'; document.body.appendChild(newDiv);}()"
EmbedScriptFromFile Method
Description
Runs the JavaScript stored in the specified file each time a page or frame loads or refreshes in the browser.
Syntax
object.EmbedScriptFromFile FileName
Arguments
Parameter | Description |
---|---|
FileName |
Required. A String value. The full path of the JavaScript file to run. The location can be an absolute or relative file system path or an ALM path. |
Return Type
None
IMPORTANT
- The JavaScript file remains embedded in the Web page until you close the browser, or until the run session ends.
- Using this method to perform alert operations may result in unexpected behavior.
- The function that embeds the JavaScript file may be called more than once. Make sure that this does not result in unwanted functionality. For example, if relevant, you may want to design the JavaScript file itself so that it will only be loaded if it is not already included in the Web page.
- This method embeds a JavaScript from a specified file. To embed a script directly as the argument value, use the EmbedScript method.
- To run this method, the security settings in your Web browser must be set to allow active scripting. Otherwise, steps using this method will fail.
Example
The following example uses the EmbedScriptFromFile method to embed a jQuery function in the browser, and then uses the RunScript method to retrieve the number of search results found in a Web search engine.
It then calculates the last 10 results, navigates to a new page, and displays the specified results.
Sub EmbedScriptFromFile_Example() 'Embed the jQuery script Browser("MySearchEngine").EmbedScriptFromFile "c:\jquery-1.3.2.js" searchTerm = "EmbedScript QTP" Browser("MySearchEngine").Page("MySearchEngine").WebEdit("q").Set searchTerm Browser("MySearchEngine").Page("MySearchEngine").WebButton("Search the Web").Click 'Find the resultStats element with the 3rd bold tag (zero based) under it, and get the text resultCount = Browser("MySearchEngine").Page("MySearchEngine").RunScript("(function(){$('#resultStats').children('b').eq(2).text()}();") 'Calculate the location of the 10th to last result lastPage = CLng(resultCount) - 10 'Navigate to a new page, and instruct the browser to display the last 10 results Browser("MySearchEngine").Navigate "http://www.MySearchEngine.com/search?hl=en&q=" & searchTerm & "&start=" & lastPage & "&filter=0"End Sub
Forward Method
Description
Navigates to the next page in the browser history list.
Syntax
object.Forward
Return Type
None
IMPORTANT
This method is identical to clicking the browser's Forward button.
Example
'The following example uses the Forward method to navigate to 'the following page after the Back method has been used. Browser("Mercury Tours").Page("Find Flights").Image("findFlights").Click 103, 13 Browser("Mercury Tours").Back Browser("Mercury Tours").Page("Find Flights").WebRadioGroup("seatType").Select "Coach" Browser("Mercury Tours").Forward Browser("Mercury Tours").Page("Search Results").Check CheckPoint("Search Results")
FullScreen Method
Description
Sets the browser's full-screen mode off or on or toggles it.
Syntax
object.FullScreen mode
Arguments
Parameter | Description |
---|---|
mode |
Optional. A String value. Specifies whether to toggle the browser's full-screen mode or to set the full-screen mode on or off. Possible values: FULL_SCREEN_ON. Turn on full-screen mode. FULL_SCREEN_OFF. Exit full-screen mode. FULL_SCREEN_TOGGLE (Default). Toggle the full-screen mode. |
Return Type
None
IMPORTANT
This method is not recorded on Firefox browsers.
Example
'The following example uses the FullScreen method to toggle the full-screen mode. 'If the browser is in full-screen mode when you run this, it will exit full-screen mode. 'Otherwise it will turn on full-screen mode. Browser("Web Testing").FullScreen
GetDialogText Method
Description
Retrieves the text displayed in a browser dialog box such as alert, confirmation, or prompt.
Syntax
object.GetDialogText
Return Type
A String value.
IMPORTANT
- This method is used in Mozilla Firefox versions 4 and higher to replace the use of the Dialog("").Page("").<Web element> syntax in your test or component. Any existing tests and components last modified in Firefox versions earlier than 4 may need to be updated to run steps on Firefox versions 4 and higher.
- This method is supported on Google Chrome versions 26 and higher.
Example
'The following example uses the DialogExists method to verify whether a browser dialog box '(such as an alert, confirmation, or prompt) exists. If the dialog box does exist, it uses 'the GetDialogText method to retrieve the message displayed, and then it uses the HandleDialog 'method to click the OK button and close the dialog box. If Browser(“B”).DialogExists then Print Browser(“B”).GetDialogText Browser(“B”).HandleDialog End If
HandleDialog Method
Description
Clicks a button on the browser dialog box (alert, confirmation, or prompt) after entering a value if necessary.
Syntax
object.HandleDialog ([button], [Value])
Arguments
Parameter | Description |
---|---|
button |
Optional. A micDialogButton Value. Default value = 0 |
Value |
Optional. A Variant. |
Return Type
None.
IMPORTANT
- This method is used in Mozilla Firefox versions 4 and higher to replace the use of the Dialog("").Page("").<Web element> syntax in your test or component. Any existing tests and components last modified in Firefox versions earlier than 4 may need to be updated to run steps on Firefox versions 4 and higher.
- This method is supported on Google Chrome versions 26 and higher.
Example
'The following example uses the DialogExists method to verify whether a browser dialog box '(such as an alert, confirmation, or prompt) exists. If the dialog box does exist, it uses 'the GetDialogText method to retrieve the message displayed, and then it uses the HandleDialog 'method to click the OK button and close the dialog box. If Browser(“B”).DialogExists then Print Browser(“B”).GetDialogText Browser(“B”).HandleDialog End If
Home Method
Description
Navigates to the home page configured in the browser's settings.
Syntax
object.Home
Return Type
None
IMPORTANT
- This method is identical to clicking the browser's Home button.
- This method is not supported for recording on Mozilla Firefox or Google Chrome.
- This method is not supported on Google Chrome.
Example
'The following example uses the Home method to return to the 'browser's default Home page. Browser("Web Testing").Home
IsSiblingTab Method
Description
Indicates whether the specified tab is a sibling of this tab object in the same browser window.
Syntax
object.IsSiblingTab (BrowserObject)
Arguments
Parameter | Description |
---|---|
BrowserObject |
Required. An Object. The browser test object representing a different tab in the same browser window. |
Return Type
A Boolean value.
Example
'The following example uses the IsSiblingTab method to check if two tabs exist in the same browser. Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20 Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5 'Open another tab in the browser Browser("Mercury Tours").OpenNewTab 'Perform an operation on the second tab Browser("Google Browser").Page("Google").WebEdit("q").Set "Hello World" 'Check if the two tabs are in the same browser. This should return True. Result = Browser("Mercury Tours").IsSiblingTab(Browser("Google Browser")) MsgBox Result
Maximize Method
Maximizes the browser window.
Syntax
object.Maximize
Return Type
None
IMPORTANT
This method is not recorded.
Minimize Method
Minimizes the browser window to an icon.
Syntax
object.Minimize
Return Type
None
IMPORTANT
This method is not recorded.
Navigate Method
Description
Opens a specified URL in the browser.
Syntax
object.Navigate Location, [TargetFrame], [PostData], [Headers]
Arguments
Parameter | Description |
---|---|
Location |
Required. A String value. The URL to open in the browser. |
TargetFrame |
Optional. A String value. The frame to which the URL will be sent. Note: The frame name is specified in the NAME argument of the <FRAME> tag in the HTML source. Default value = "_top" |
PostData |
Optional. A String value. The data that accompanies a Post request. Default value = "" |
Headers |
Optional. A String value. Any header data, such as cookies and content-type. Default value = "" |
Return Type
None
IMPORTANT
Use the default value of the Headers parameter if you use the latest Micro Focus UFT Agent Chrome extension (MV3).
The TargetFrame and PostData parameters are supported on Internet Explorer only.
Example
'The following example uses the Navigate method to navigate to the 'Mercury Interactive Web site. Browser("Mercury Tours").Navigate ("www.merc-int.com")
OpenNewTab Method
Description
Opens a new tab in the browser window.
Syntax
object.OpenNewTab
Return Type
None
IMPORTANT
On Safari, the new tab navigates to the URL for new tab, defined in the Safari extension's preferences. For details, see the UFT One Help Center.
Example
'The following example uses the OpenNewTab method to open a new tab in a browser. Browser("Mercury Tours").Page("Search Results").Image("reserveFlights").Click 41, 20 Browser("Mercury Tours").Page("Method of Payment").Image("buyFlights").Click 11, 5 'Open another tab in the browser Browser("Mercury Tours").OpenNewTab 'Perform an operation on the second tab Browser("Google Browser").Page("Google").WebEdit("q").Set "Hello World"
Quit Method
Closes all active browser tabs and windows, and kills any browser-related processes.
Syntax
object.Quit
Return Type
None
Refresh Method
Description
Refreshes the current page.
Syntax
object.Refresh
Return Type
None
IMPORTANT
This method is identical to clicking the browser's Refresh button.
Example
'The following example uses the ClearCache method to clear the cache from the browser, 'and then uses the Refresh method to refresh the objects in the browser. Browser("Mercury Tours").ClearCache Browser("Mercury Tours").Refresh
Restore Method
Restores the browser window to its previous size.
Syntax
object.Restore
Return Type
None
IMPORTANT
This method is not recorded.
Sync Method
Description
Waits for the browser to complete the current navigation.
Syntax
object.Sync
Return Type
None
IMPORTANT
You can use this method to instruct your test to wait until the browser is loaded.
For Mozilla FireFox, this method is recorded as a Page.Sync method.
Example
'The following example uses the Sync method to wait for the Mercury Tours site to load in the browser. Browser("Mercury Tours").Navigate ("www.merc-int.com") Browser("Mercury Tours").Sync
See also: