I am trying to script for the "File-->Save As" feature in IE. It had been working previously in my script but no longer. The problem centers around the object 'contextmenu', which a layman might call a dropdown menu.
The code that was generated and previously reliable:
Browser("Browser").WinToolbar("ToolbarWindow32").P ress "&File"
Browser("Browser").WinMenu("ContextMenu").Select "Save As..."
Browser("Browser").Dialog("Save Web Page").WinComboBox("Save as type:").Select "Text File (*.txt)"
Browser("Browser").Dialog("Save Web Page").WinListView("SysListView32").Select "ExistingFileName"
Browser("Browser").Dialog("Save Web Page").WinButton("Save").Click
Browser("Browser").Dialog("Save Web Page").Dialog("Save Web Page").WinButton("Yes").Click
When it fails, QTP displays the message:
The "ContextMenu" object was not found in the Object Repository. Check the Object Respository to confirm that the object exists or to find the correct name for the object.
Well, the Contextmenu object does exist in the OR with the following properties:
menuobjtype = 3
ordinal identifier: none
The 'Spy' utility doesn't help because the simple act of activating another application (i.e. Spy) makes the contextmenu disappear.
Set theTestObject =Window("a").Window("b").WinButton("Button").WinMe nu("ContextMenu")
Set Props = theTestObject.GetTOProperties
PropsCount = Props.Count
For i = 0 To PropsCount - 1
PropName = Props(i).Name
PropValue = Props(i).Value
MsgBox PropName & " = " & PropValue
but I'm unsure what to use for the TestObject.
Set theTestObject = Browser("MyBrowser").WinToolbar("ToolbarWindow32") .????????
Set theTestObject = Browser("MyBrowser").WinToolbar("ToolbarWindow32") .WinMenu("ContextMenu") but of course if it didn't
recognize the Object "contextmenu" in the first place, it won't give me properties.
So I have the dilemma of needing a property to identify the ContextMenu so I can find some properties to help identify the ContextMenu.
OK, I've done some legwork and now put out a cry for help to the rest of you.
Re-record yourself clicking those same steps in the same context menu.
This will cause QTP to add the context menu to the OR again. Sometimes, this reveals that something has changed because it uses different recognition properties, or the same properties have different values.
Sometimes it helps to delete the old object from the OR before re-recording, but if the recognition really has changed, QTP will just stick it into the OR as "ContextMenu_2" anyway - so you can compare the two versions of the OR object and see what changed. Then just delete the old one and rename the new one to get rid of the "_2" from the name.
This doesn't always works, but it works for me most of the time.