Micro Focus QTP (UFT) Forums
Sendkeys to close an open web browser - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Sendkeys to close an open web browser (/Thread-Sendkeys-to-close-an-open-web-browser)



Sendkeys to close an open web browser - prasadworld321 - 03-05-2010

How to activate a web browser and sendkeys for closing it?
i have written the script as follw

Code:
Set WshShell = CreateObject("WScript.Shell")

Browser("name:=Google").Activate
wait(3)
WshShell.SendKeys ("%{F4}")


But it is not working.....
WORNING: no method like 'Activate' for web page

can anybody correct it??

Thanks


RE: Sendkeys to close an open web browser - wheelercha - 03-05-2010

This will close the last opened browser.

Code:
Function CloseLastOpenedBrowser()

Dim oDescription
Dim BrowserObjectList
Dim oLatestBrowserIndex

Set oDescription=Description.Create
oDescription("micclass").value="Browser"
Set BrowserObjectList=Desktop.ChildObjects(oDescription)
oLatestBrowserIndex=BrowserObjectList.count-1

Browser("creationtime:="&oLatestBrowserIndex).close

Set oDescription=Nothing
Set BrowserObjectList=Nothing
Print "Close Category Total Report browser pdf"
Reporter.ReportEvent 0, "Browser PDF" , "Report closed successfully"


End Function



RE: Sendkeys to close an open web browser - prasadworld321 - 03-05-2010

Thanks.

it is working perfectly.
But i need to check the functionality of (Alt+F4)
Here i want to use the Key (Alt+F4) to close a web page in internet explorer 7.
Please guide me how to use the 'Sendkeys' method