Browser Functions not getting invoked in InPrivate Browsing Mode of IE?

Recently, I came across a situation in which I have to automate some scenario on private browsing mode of Internet Explorer (known as InPrivate Browsing). Although browser was getting identified in that mode, browser methods (like navigate,refresh etc) were not working (not throwing any error). After some searching, I came to know that in InPrivate Browsing Mode, all the extensions and add-ins are disabled due to which BHOManager Class Add-In is also disabled.

To enable browser methods in InPrivate mode of Internet Explorer, we need to enable add-ins. To do that, follow the below steps:

  • Go to Tools > Internet Options and click on Privacy tab.
  • Under the InPrivate section, uncheck the option that says ‘Disable toolbars and extensions when InPrivate Browsing starts’.
  • Click on OK button and start InPrivate session.

Image

Tagged with: , , , , , ,
Posted in Awesum Stuff

How to fix missing menu options in QTP

Many times menu items in QTP don’t show and appear blank (shown in below screenshot)

Image

Today, we’ll see how to fix this issue. To fix this issue:

  • Right click on the toolbar (where File, Edit, View etc menu is appearing) and click on Customize option

Image

  •  Click on Restore All in Toolbars tab:

Image

Isue will be fixed :)

Tagged with: , , , , , ,
Posted in Common Issues

How to clean invisible characters from string using VBScript

</p><p> </p><p>Public Function strClean(strToClean)
    Dim inStringArray()
    ReDim inStringArray(len(strToClean) - 1)
    For iterator = 1 to Len(strToClean)
        currentChar = Mid(strToClean, iterator, 1)
        currentCharASCII = Asc(currentChar)
        If currentCharASCII = 0 OR (currentCharASCII >= 7 AND currentCharASCII <= 13) OR currentCharASCII = 27 OR currentCharASCII = 63 Then
            inStringArray(iterator - 1) = ""
        Else
            inStringArray(iterator - 1)=currentChar
        End If
    Next
    strClean = Join(inStringArray, "")
End Function</pre>
&nbsp;

&nbsp;

Tagged with: , , ,
Posted in Code Vault

Automating Microsoft Excel Part 4 – How to Automate MS Office Ribbon

If you are banging your head(which I quite frequently do) with GUI Automation of a Microsoft Office application, then this post is a must for you. QTP’s object Spy does not identify any of the Ribbon controls in any Office application. So, in order to click on any button in the ribbon, rather than relying on Sendkeys method, one can use the Command Bars Collection Object for accessing these buttons.

Here’s an example of how to use this in Microsoft Excel :-


Set objExcel=CreateObject("Excel.Application")

Set objBook= objExcel.Workbooks.Add

Set objSheet=objBook.Worksheets(1)

'Finding out the correct names of the Controls in the Command Bars collection

For i = 1 to objExcel.CommandBars("Worksheet Menu Bar").Controls.count

Print objExcel.CommandBars("Worksheet Menu Bar").Controls(i).Caption

Next

'For example, if you want to simulate the clicking of Insert -> Chart button in the ribbon, from the above code you can find out on which index '"Insert" button will come (it comes on i=4), after that we can iterate to Insert control's sub controls in order to find out the correct 'index/name of the required control :-

For i = 1 to objExcel.CommandBars("Worksheet Menu Bar").Controls(4).Controls.Count

Print objExcel.CommandBars("Worksheet Menu Bar").Controls(4).Controls(i).Caption

Next

'After finding out the correct index for the Insert Chart button, we can simulate clicking on it in the following manner :-

objExcel.CommandBars("Worksheet Menu Bar").Controls(4).Controls(5).execute

'Please note that we can also use the Caption instead of the Index :-

objExcel.CommandBars("Worksheet Menu Bar").Controls("&Insert").Controls("C&hart...").execute

The above code can be used for any Office application like PowerPoint,Word,Outlook etc. For more details on the Command Bars and Command Bar controls, you can visit the following links :-

http://msdn.microsoft.com/en-us/library/office/aa190804(v=office.10).aspx

http://msdn.microsoft.com/en-us/library/office/aa831765(v=office.10).aspx

 

PS: In UFT, all the ribbon controls are identified as WinButtons, so clicking on any Ribbon control is as easy as clicking on any button in a Web app.

Happy Automating !

Harshit Kohli

Tagged with: , , , , , , , , ,
Posted in Awesum Stuff

How to save file at desired location using QTP

While scripting for web application, one always faces an issue in selecting a folder location to save the file. Suppose, script clicks on download button on the page to download a file) and then presented with the Save as dialog box (shown below) that shows after clicking on the Save button.

Image

Now, to save file to desired location (suppose Desktop), Desktop icon on the left side of the dialog box needs to be clicked.

To do this, we only need to type or set the full path of the desired location along with the file name in the File Name field in the Dialog Box and then click on Save button

To save the file in Downloads folder on Desktop, just Read more ›

Tagged with: , , ,
Posted in Awesum Stuff

How to delete Registry Key using QTP/VBScript?

As I have already talked about How to read/modify and create Registry Settings in previous posts, today I will be talking about how to delete Registry Keys. Again, there are 2 ways to delete Registry Keys:

  • Using VBScript: This method only works for keys with no child key or subkey

 Dim objShell, RegLocate

 'create windows shell object
 Set objshell =CreateObject("WScript.Shell")

 RegLocate ="HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr"
 'Reading Registry will throw an error if path doesn't exists
 On Error Resume Next
 reg_value=objshell.RegRead (RegLocate)
 On Error Goto 0
 'check for the error and then delete if it exists (error number is 0)
 If Err.Number = 0 Then
 objShell.RegDelete RegLocate
 Else
 msgbox "Registry does not exists"
 End If
 Set objshell = Nothing

  • Using WMI: This method also works if there are subkeys for a key

 Const HKCU = &H80000001
 Dim objReg
 strComputer = "."
 Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 objReg.EnumKey HKCU, strKeyPath, arrSubkeys
 If IsArray(arrSubkeys)=True Then
 For Each strSubkey In arrSubkeys
 DeleteSubkeys HKCU, strKeyPath & "\" & strSubkey
 Next
 End If
 objReg.DeleteKey HKCU, strKeyPath

Tagged with: , , , , , ,
Posted in Awesum Stuff

How to prevent “Restore your Session” dialog box after being restarted on crashing?

restore session

We, as an Automation Testers, while automating Web Application must have faced browser crash due to which, after restarting Internet Explorer comes an dialog box which asks to:

  • Either Restore Last Session
  • or Go to Home Page (screenshot below)

Image

Now, this pop up can be prevented by going to Tools > Internet Options > Advanced tab and uncheck Enable Automatic Crash Recovery option under Browsing section. This, inturn can be achieved either Manually or Automatically. However, doing it Manually is a tedious task as before running script on any machine, you need to do the above mentioned setting to prevent this dialog.

We can achieve this Automatically (doing this automatically keeps you headache free to do setting on every machine) by doing some Registry Tweaking as explained in one of my previous article.

Registry Key correspoding to above setting is: HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Recovery\AutoRecover

Setting the Registry Value to:

  • 0 displays the notification to either restore previous session or go to homepage
  • 1 always Restore Previous Session
  • 2 always Go to Home Page

Note: Here, we are setting the Registry Value to 2 (always go to home page)


Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Policies\Microsoft\Internet Explorer\Recovery"
strValueName = "AutoRecover"

'storing the value of strValueName from strKeyPath in dwValue
objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'checking if Registry Key Exists
If cstr(IsNull(dwValue))="True" or cstr(objRegistry.EnumKey(HKEY_CURRENT_USER,strKeyPath,arrSubKeys)) <> "0" Then

msgbox "The registry key does not exist."

'setting 1 for strValueName in strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,2

objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'checking if Registry Key still exists
If cstr(IsNull(dwValue))="True" Then

'If Registry Key still doesn't exists, then it means strKeyPath does not exist, need to create key first
objRegistry.CreateKey HKEY_CURRENT_USER,strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,2
objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
msgbox dwValue
Else
msgbox "The registry key exists."
End If
Else
msgbox "The registry key exists."
End If

Tagged with: , , , , , , ,
Posted in Common Issues
Blog Stats
  • 50,502 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 587 other followers

Follow

Get every new post delivered to your Inbox.

Join 587 other followers

%d bloggers like this: