Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
08-21-2009, 10:57 AM
(08-21-2009, 10:12 AM)Saket Wrote: Hi Smita,
would you like to use Windows API in your script?
Try this - Paste the following code into your script or in a library file and call the function 'HandleDialog' where you want to handle the dialog
Code: Extern.Declare micHwnd, "FindWindowEx", "user32.dll", "FindWindowExA", micHwnd, micHwnd, micString, micString
Extern.Declare micLong, "PostMessage", "user32.dll", "PostMessageA", micHwnd, micLong, micLong, micLong
Extern.Declare micLong, "GetWindow", "user32.dll", "GetWindow", micLong, micLong
Const BM_CLICK = &HF5
Const WM_SETFOCUS = &H7
Public Function HandleDialog()
pHwnd = extern.FindWindowEx(0,0, vbNullString, "Microsoft Internet Explorer")
'pHwnd = extern.FindWindowEx(0,0, vbNullString, "Message from webpage")
extern.PostMessage pHwnd,WM_SETFOCUS,0,0
If pHwnd > 0 Then
btnHwnd = extern.FindWindowEx(pHwnd,0,"button" ,vbNullString)
extern.PostMessage btnHwnd,WM_SETFOCUS,0,0
wait(5)
extern.PostMessage btnHwnd,BM_CLICK,0,0
End If
End Function
Let me know if there is any issue
Saket -
This is a nice piece of code. I was just wondering would it not treat IE as a window since "Microsoft Internet Explorer" is the tag we are providing to search for ?
Smita -
did any of the other solutions help you so far ?
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 1,199
Threads: 5
Joined: Nov 2008
Reputation:
0
08-21-2009, 11:02 AM
(This post was last modified: 08-21-2009, 11:03 AM by Saket.)
Basanth - unfortunately I dont have IE6 on my machine now, so not able to try with that. but I am sure that It will treat IE as a window because I think whenever we open an application in IE it takes the name of application as well so until unless we will not pass the whole name or in regualae expression, it will not the the IE, I think the caption comes as - '<<App Name>> - Microsoft Internet Explorer'
hope you are getting what i am trying to explain
Sory Typo - Please read ' It will treat IE as a window because ' as It will not treat IE as a window because '
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
08-21-2009, 11:20 AM
Yeah got it. I do that typo and if you dont notice it, it gives a total different meaning. Well i guess the risk we have to take is that the app name is being displayed on the title which i hope every developer thinks as a basic common sense during coding
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 20
Threads: 2
Joined: Apr 2008
Reputation:
0
08-24-2009, 04:06 PM
Thanks a lot to you basanth, your last solution really worked well.
This issue got solved which was pending for very very long time.
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
08-24-2009, 06:38 PM
Excellent !!!
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 1,105
Threads: 18
Joined: Jan 2008
Reputation:
8
08-24-2009, 07:03 PM
Basanth,
You may want to write a quick explanation of your approach for everyone (like how you are activating the window , also it would be good to have a link to MSDN for the method used ). We can then stick this thread on top of sub-forums "QTP Others" and make the thread title bit more related to the question asked by OP.
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
08-24-2009, 07:44 PM
(This post was last modified: 08-24-2009, 07:51 PM by basanth27.)
Code: Set fso = CreateObject("WScript.Shell")
While fso.AppActivate("Your Window Name") = FALSE
wscript.sleep 1000
Wend
fso.SendKeys "a", True
fso.SendKeys "N", True
wscript.sleep 7000
While fso.AppActivate ("Your Window Name") = FALSE
wscript.sleep 1000
Wend
fso.SendKeys "N", True
Ugh...I wrote a lot and everything seems to have got deleted other than the Code :-).
Okay i am going to rewrite the whole stuff.
There are several instances when QTP hangs due to a window appearing on the screen. Reasons debated being several, the core issue is derieved from the very fact about the outlook security window which appears and freezes the qtp script. To negate this situation a execution of a external vbs file which parallelly works to counter the windows presence and hence closing it through the keystrokes helps qtp to proceed further.
1. Save the above code as dialoghandler.vbs on your c:\ drive.
2. Be sure to modify the code to replace the window title or name.
3. Replace the appropriate keystrokes you need to send for the dialog. [ for eg :you may need to press "Enter" which inturn actually clicks on "OK" or "cancel" button.
4. Just before the line on QTP where the code executes and freezes QTP, enter this code,
SystemUtil.Run "C:\Windows\System32\Wscript.exe", "C:\dialoghandler.vbs"
This Solution was provided to me by Yaron Assa of the AdvancedQtp Fame.
Let me know if you have any questions.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 1,003
Threads: 1
Joined: Jul 2009
Reputation:
5
09-02-2009, 11:24 AM
(08-24-2009, 07:44 PM)basanth27 Wrote: [/code]Set fso = CreateObject("WScript.Shell")
While fso.AppActivate("Your Window Name") = FALSE
wscript.sleep 1000
Wend
fso.SendKeys "a", True
fso.SendKeys "N", True
wscript.sleep 7000
While fso.AppActivate ("Your Window Name") = FALSE
wscript.sleep 1000
Wend
fso.SendKeys "N", True
[code]
Ugh...I wrote a lot and everything seems to have got deleted other than the Code :-).
Okay i am going to rewrite the whole stuff.
There are several instances when QTP hangs due to a window appearing on the screen. Reasons debated being several, the core issue is derieved from the very fact about the outlook security window which appears and freezes the qtp script. To negate this situation a execution of a external vbs file which parallelly works to counter the windows presence and hence closing it through the keystrokes helps qtp to proceed further.
1. Save the above code as dialoghandler.vbs on your c:\ drive.
2. Be sure to modify the code to replace the window title or name.
3. Replace the appropriate keystrokes you need to send for the dialog. [ for eg :you may need to press "Enter" which inturn actually clicks on "OK" or "cancel" button.
4. Just before the line on QTP where the code executes and freezes QTP, enter this code,
SystemUtil.Run "C:\Windows\System32\Wscript.exe", "C:\dialoghandler.vbs"
This Solution was provided to me by Yaron Assa of the AdvancedQtp Fame.
Let me know if you have any questions.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Posts: 20
Threads: 2
Joined: Jul 2010
Reputation:
0
07-10-2010, 06:25 PM
I am not sure if this issue has been resolved. But here is another solution we tried and it works great.
Prior to the Select method, have the following code
Code: SiebelApplication("XYZ").SetTimeOut(10)
On Error Resume Next
SiebApplication ......Select "....."
On Error Goto 0
Browser()....Dialog().Click
Thanks MV
|