Understanding Browser methods, by opening multifarious Tabs of Browser in UFT
To grasp the various common methods of the Browser Object in UFT, we’ll demonstrate by opening two tabs within the same browser instance.
Scenario: How can we open webpages in different tabs of the same browser?
Solution:
- Launch the browser and open a webpage (e.g., “www.uftHelp.com“).
- Within the same instance, open another tab and redirect to a different webpage (e.g., “www.Google.com“).
To achieve this, we’ll utilize the following methods of the Browser object:
- OpenNewTab: Opens a new tab in the existing browser window.
- Navigate: Redirects to the given URL.
- FullScreen: Opens the browser in full-screen mode (F11).
- Refresh: Refreshes the opened page (similar to pressing F5).
- DeleteCookies: Deletes the cookies from the browser.
- CloseAllTabs: Closes all the opened tabs and the browser instance.
- Sync: Waits for the browser to navigate to the opened URL.
Sample Code:
'Open a new Browser using Util Object SystemUtil.Run "iexplore.exe", "www.uftHelp.com" 'Browser Sync Browser("CreationTime:=0").Sync 'Delete cookies from the Browser Browser("CreationTime:=0").DeleteCookies 'Refreshes the Opened Page Browser("CreationTime:=0").Refresh 'Opening a new tab within the same browser Browser("CreationTime:=0").OpenNewTab() 'Opening Browser in FullScreen mode Browser("CreationTime:=0").FullScreen 'Sync for new tab Browser("CreationTime:=1").Sync 'Navigate to a particular URL in the new tab Browser("CreationTime:=1").Navigate "www.Google.com" 'Find the total number of tabs in the browser window iTabs = Browser("CreationTime:=0").GetROProperty("number of tabs") msgbox iTabs 'Displays the value 2 'Close all the tabs in the browser window Browser("CreationTime:=0").CloseAllTabs()