The web application that displays database information is much more readable in full-screen mode rather than a small window. Problem is, I cannot get the window to maximize from UFT/QTP.
I've tried running the browser object from Wscript.Shell, but the application returns to UFT and maximizes that window instead of the newly created browser window.
siteA = "https://google.com"
Const max_window = 3
Set browobj = CreateObject("Wscript.Shell")
Set oShell = CreateObject("WScript.Shell")
'browobj.Run "chrome -k -incognito -url "&siteA
browobj.Run "chrome -incognito -url "&siteA, max_window
oShell.SendKeys "% x"
browobj.sendkeys "{F9}"
browobj.sendkeys "(% )X"
browobj.SendKeys "% x"
Set browobj = Nothing
Any solutions to maximizing the window with the focus object of the new browser?
Edit:
Even below will not maximize taken from this List of Controls is not working.
SystemUtil.Run "chrome.exe" , siteA ,,,3
chrome.exe --incognito --start-maximized
If you shut down all instances of chrome these controls work fine, but if you have an active window in chrome it will take those properties.
We have a function defined during our browser login process that grabs the window and maximises it so that our UFT processes run with a (nearly) full screen browser - we don't need to hide the menu bar etc. This is the function we are using:
Public Function MISC_MaximiseBrowser(ByVal oBrowser, ByRef ErrorMsg)
LOG_Write vbNewLine & "MISC_MaximiseBrowser"
LOG_Write "oBrowser: " & oBrowser.GetROProperty("TestObjectName")
Dim Hwnd
dim bIsMax, bIsMaxable
MISC_MaximiseBrowser = True
Hwnd = oBrowser.Object.HWND
If Window("hwnd:=" & Hwnd).GetROProperty("maximized") Then
bIsMax = True
Else
bIsMax = False
End If
If Window("hwnd:=" & Hwnd).GetROProperty("maximizable") Then
bIsMaxable = True
Else
bIsMaxable = False
End If
If Not bIsMax And bIsMaxable Then
Window("hwnd:=" & Hwnd).Maximize
End If
End Function
What this does is accepts the Browser UFT object you're working with and grabs the handle for it. If the browser is not already maximized and it's possible to maximize it, it will do so.
You can ignore the LOG_Write statements at the start of the function - those are for our internal logging steps
Related
I have an application that opens up some new tabs. I'm trying to cycle through these tabs, look at them, and then close them.
Dim tab_children, oDesc
Set oDesc = Description.Create
oDesc("micclass").value = "Browser"
Set tab_children = Desktop.ChildObjects(oDesc)
Dim title, handle, cTime
For i = 0 To tab_children.Count-1 Step 1
title = tab_children(i).GetROProperty("title")
handle = tab_children(i).GetROProperty("hwnd")
Window("hwnd:=" & handle).Restore
msgbox title & ": " & handle
Next
When we try to execute the .Restore, I receive an "object not visible" error. The tab that we're trying to restore is not the one that has focus, could that be the issue and if so how can we resolve it? I was under the impression that .Restore would bring that tab into focus based off of this thread, http://www.advancedqtp.com/old_forums/viewtopic.php?t=1970
The IDE I'm using is QTP, the Browser is IE.
A potential work around that I've been thinking about:
After the application opens up the new tabs, the last opened tab has focus. If we close that one, the 2nd to last has focus, all the way down to the original application's tab. Perhaps there's a way to utilize this information.
Restore has worked for me in the past, try using Activate-
Window("hwnd:=" & handle).Activate
Edited: Just tested the following and its working on my machine-
'Create Browser Descriptor
Set oBrowser=Description.Create
oBrowser("micclass").Value="Browser"
'Get the child objects
Set oBrowser=Desktop.ChildObjects(oBrowser)
totalcount = oBrowser.Count-1
For i=0 to totalcount
If Browser("micclass:=Browser", "index:="&i).Exist(0) Then
'get the hwnd everytime there's an iteration
ohwnd= Browser("micclass:=Browser", "index:=" & i).GetROProperty("hwnd")
'For debugging purposes
name = Browser("hwnd:="&ohwnd).GetROProperty("title")
msgbox name
Set oBrowser=Browser("hwnd:="&ohwnd)
'Page descriptor
Set oPage=Description.Create
oPage("micclass").Value="Page"
Set oPage=Browser("hwnd:="&ohwnd).ChildObjects(oPage)
For n=0 to oPage.Count-1
If oPage(n).Exist(0) Then
oBrowser.Close
Exit For
End If
Next
End If
Next
If you want to close only a particular page you can use the GETROPREPERTY("Title") in the If loop - If oPage(n).Exist(0)
I would like to control the zoom in and out feature of my webpage of the application under test using UFT. This is required as the zoom level changes dynamically and it becomes difficult to identify the objects.
I have found a code but it is useful if you need to change the zoom level at one instance or at the start. below is the code
Function ChangeIEZoom
Dim intZoomLevel, objIE
intZoomLevel = 110
Const OLECMDID_OPTICAL_ZOOM = 63
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate ("www.google.com")
While objIE.Busy = True
wait 5
Wend
objIE.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(intZoomLevel), vbNull
End Function
with this code, it opens up a new browser and navigates it to a URL.
I do not want it to create a new instance of the browser.
What I need is that it changes the zoom level on the same page which is already under test execution, also the page where zoom level change is required not known at the start and it may or may not require change based on the fact that it identifies certain objects.
Has anyone faced the same issue or has a solution to it ?
I found a solution - combining what you mentioned in comments. this works if you want to change the zoom level on current webpage you are working on. helps when you want to zoom in and out at multiple instances
Dim ShellApp
Set ShellApp = CreateObject("Shell.Application")
Dim ShellWindows
Set ShellWindows = ShellApp.Windows()
Dim intZoomLevel
intZoomLevel = 110
Const OLECMDID_OPTICAL_ZOOM = 63
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Dim i
For i = 0 To ShellWindows.Count - 1
If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
Set IEObject = ShellWindows.Item(i)
End If
If IEObject.Visible = True Then
While IEObject.Busy = True
wait 5
Wend
IEObject.ExecWB OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, CLng(intZoomLevel), vbNull
End If
Next
print "it works"
I have a vbscript that opens an webpage, then clicks a button. That button opens a new popup webpage on a new window (notice: window not tab).
I want after my script press the button and open a new window, to detect and click the button called id="pagesHeaderLikeButton" in that new window, then close that window.
My script so far:
Set IE = createobject("internetexplorer.application")
strURL = "website"
Do While True
IE.navigate strURL
IE.Visible = true
Do While (IE.Busy Or IE.READYSTATE <> 4)
WScript.Sleep 1000
Loop
Set Popupbutton = IE.Document.GetElementsByClassName("single_like_button btn3-wrap")
for each button in Popupbutton
button.click
WScript.Sleep 5000
exit for
objWindow.Quit
WScript.Sleep 5000
next
Loop
Also to notice. I want to do it like this because the popup window allways will have a new url.
For Each wnd In CreateObject("Shell.Application").Windows
If InStr(wnd.Name,"Internet") Then
if InStr(wnd.Document.URL,"facebook.com") Then
Set IE2 = wnd
Exit For
End If
End If
Next
The above script will find any opened IE with the URL: facebook.com/*** and will set IE2 to be that opened IE.
So to press the button:
Set Butlike = IE2.Document.getElementsById("pagesHeaderLikeButton")
For Each btn In Butlike
button.click
Next
I am new to vbscript. I want to save a snapshot taken using vbscript of a internet explorer window opened by vbscript.
Code to load the page
Dim IE, stateString
Set IE = WScript.CreateObject("InternetExplorer.Application")
ie.toolbar = 1
ie.statusbar = 1
ie.width = 999
ie.height = 500
ie.left = 20
ie.theatermode = false
ie.theatermode = true
ie.theatermode = false
ie.top = 50
ie.navigate("file:///C:\Users\Vinit_Tiwari\Documents\vbscripts\someform.html")
'stateString = cstr(ie.readystate)
waitforload(ie)
ie.visible = 1
Set wshShell = CreateObject("Wscript.Shell")
wshShell.AppActivate "Some Form"
wshShell.SendKeys "% x"
Code to take snapshot
Dim oWordBasic
set oWordBasic = CreateObject("Word.Basic")
oWordBasic.sendkeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"
Set oWordBasic = Nothing
Wscript.Sleep 2000
Saving the snapshot
dim paint
set paint = wshShell.exec("mspaint")
do while paint.status = 0:loop
wshShell.appactivate("untitled-Paint")'this returns false
Wscript.sleep 500
WshShell.SendKeys "^v"
wscript.sleep 500
wshshell.sendkeys "^s"
wscript.sleep 500
wshshell.sendkeys "d:\test.png"
wscript.sleep 500
wshell.sendkeys "{Enter}"
Set wshshell = Nothing
Actually the previously opened ie window is having focus and the keystrokes are sent to the ie instead of paint. so is there any function which performs opposite work of AppActivate.
This won't work. Microsoft Word is in focus while the Print Screen button is pressed. You can easily eliminate this problem by not using Microsoft Word at all. It's not necessary. The Print Screen function is a system hotkey and has nothing to do with Microsoft Word. You should be using the Alt+PrintScreen combination which captures a screenshot of the currently focused window to the clipboard.
Second, if Paint is not in focus instead of IE, it's because you have the window title wrong. You are doing that part correctly. AppActivate returns false if it cannot find a window with the specified title. To be honest, Paint should alread have focus to begin with but it is good practice to make sure the window is activated first.
Also, is this a very old system? Why are you using the Word.Basic automation object anyway out of curiosity?
I'm trying to run an automated vbs script that clicks on a link on a page. I have things of the form:
Const READYSTATE_COMPLETE = 4
Set IE = CreateObject("INTERNETEXPLORER.APPLICATION")
IE.Visible = true
IE.navigate ("http://mywebpage.com")
How do I then make it click on a link on that page that doesn't have an ID but is like
ClickMe!
Thanks!
Along the lines of
Dim LinkHref
Dim a
LinkHref = "link"
For Each a In IE.Document.GetElementsByTagName("A")
If LCase(a.GetAttribute("href")) = LCase(LinkHref) Then
a.Click
Exit For ''# to stop after the first hit
End If
Next
Instead of LCase(…) = LCase(…) you could also use StrComp(…, …, vbTextCompare) (see StrComp() on the MSDN).