My Blog List

Wednesday, January 2, 2013

Change IE Browser ZOOM settings

Lot of UI automation testers could have faced this problem as we could change the zoom settings while operating manually for our convenience and forgot to reset to 100%.
But our QTP and some other related tools would operate the browser perfectly if browser zoom is 100%. So wee need to change the zoom before start to run the scripts. Its better to have a code snippet in our framework to change this zoom setting right?
Here we go...

1. We can simply change the Registry values before Invoking IE
  1. Function ChangeRegistry
  2.  Dim objShell
  3.  Set objShell = CreateObject("WScript.Shell")
  4.  objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Zoom\ZoomFactor""100000""REG_DWORD"
  5.  Set objShell = Nothing
  6. End Function
This option is very useful. But in real time, lot of customers could have restricted write access to windows registry. So we can try other options.

2. Use IE COM object and Change Settings
  1. Function ChangeIEZoom
  2.  Dim intZoomLevel, objIE
  3.  intZoomLevel = 100
  4.  Const OLECMDID_OPTICAL_ZOOM = 63
  5.  Const OLECMDEXECOPT_DONTPROMPTUSER = 2
  6.  Set objIE = CreateObject("InternetExplorer.Application")
  7.  objIE.Visible = True
  8.  objIE.Navigate "http://www.google.com"
  9.  While objIE.Busy = True
  10.   WScript.Sleep 100
  11.  Wend
  12.  objIE.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(intZoomLevel), vbNull
  13. End Function
Warnings:
1. Don't use Top, Left, Width and Height properties
objIE.Left = 0
objIE.Top = 0
objIE.Width = 1304
objIE.Height = 768

These things will not change zoom settings but sets the IE window size. You can use to maximize the IE window.
2. Don't use zoom property of page
document.body.style.zoom=1
This will not change the IE browser zoom setting but changes the currently displayed page size by keeping the same IE zoom.