How to programatically position and resize IE11

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Heinz57
Junior Coder
Posts: 28
Joined: Wed Jul 22, 2015 6:10 pm
Location: A Berliner just east of Wien

How to programatically position and resize IE11

Post by Heinz57 » Wed Jul 29, 2015 5:12 am

Hello,

I am trying to position and resize IE11 via the following code to default values but for some reason this does not seem to work:

Code: Select all

SRT>IECreateNew
IECreate>IE[0]
Let>currIE=IE[0]

//Originally via GetClipBoard>currURL,0 from the DBApp
Let>currURL=%IECreateNew_Var_1%
IENavigate>currIE,currURL,res
Gosub>IEWaitForIE

// Move IE window to pos 1,1 - DOES NOTHING
Let>WIN_USEHANDLE=1
MoveWindow>currIE,1,1
Gosub>IEWaitForIE

// Resize IE window to 1100,1000 - DOES NOTHING
Let>WIN_USEHANDLE=1
ResizeWindow>currIE,1100,1000 
Gosub>IEWaitForIE

// This is my work-around in a sub-routine which reads and presses the button on the favorites with the JS as shown below
Gosub>IEPressButtonPosition
END>IECreateNew
I found no solution to this when carefully reading the manual and the forum,

I found a work-around in IEPressButtonPosition, which is viable for us only at the moment as long as the tasks run in our VM. We added a button to the IE's favorites row, which is pressed and contains the following code:

Code: Select all

javascript:resizeTo(1100,1100);moveTo(1,1)
But this will no longer be an acceptable work-around when this code is finally deployed to customers.

Best regards
Heinz57

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: How to programatically position and resize IE11

Post by hagchr » Wed Jul 29, 2015 8:17 am

Hi, Not sure if you can use the IE[0]/currIE handles directly. If you get a handle through GetActiveWindow then it works better.

Code: Select all

IECreate>IE[0]
Let>currIE=IE[0]

Let>WIN_USEHANDLE=1
GetActiveWindow>strTitle,nXPos,nYPos,,

Let>currURL=www.wsj.com
IENavigate>currIE,currURL,res
IEWaitDocumentComplete>currIE,res

MoveWindow>strTitle,1,1
ResizeWindow>strTitle,1100,1000

Heinz57
Junior Coder
Posts: 28
Joined: Wed Jul 22, 2015 6:10 pm
Location: A Berliner just east of Wien

Re: How to programatically position and resize IE11

Post by Heinz57 » Thu Jul 30, 2015 7:02 pm

Thank you for your proposal.

However, in most of these commands access to a window can be arbitrarily by a window handle (my currIE above) OR by the window title.

Problem with the title is that:
  • it's not necessarily unique
  • it is composed by the domain's server from different elements, thus may vary substantially
But I will try ASAP and I will post the results (just aint got not time today).

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to programatically position and resize IE11

Post by Marcus Tettmar » Tue Aug 04, 2015 9:11 am

Use the GetIEHwnd function. No need to know the window title. So after using IECreate you can get its handle with GetIEHwnd and then use that in MoveWindow/ResizeWindow.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Heinz57
Junior Coder
Posts: 28
Joined: Wed Jul 22, 2015 6:10 pm
Location: A Berliner just east of Wien

Re: How to programatically position and resize IE11

Post by Heinz57 » Tue Aug 04, 2015 2:03 pm

Perfect!
Now it works.

Thank you very much.

May I just correct your little typo: The command is IEGetHWND

So in order to share this with others, here is some sample code in a subroutine that creates a new IE, loads a given url, which is passed to the sub by the sender as argument1, and then resizes the IE instance to a given default at a given hard-coded position:

Code: Select all

// Sub IECreateNew
// Create a new IE instance,store handle in currIE
// open Url, which is passed as argument1, resize and reposition new IE
SRT>IECreateNew
IECreate>IE[0]
Let>currIE=IE[0]
//Get url from arg1
Let>currURL=%IECreateNew_Var_1%
IENavigate>currIE,currURL,res
// Call my default sub for waiting to avoid many explicit waits spread through the code (= bad style)
Gosub>IEWaitForIE
// I use system variable for data and text (language independent) - one is: sysSuccessNot=1
If>res=sysSuccessNot
    // if loading IE caused an error, call this sub to handle it
    Gosub>ErrIELoading,errIENavigate
Endif
Gosub>IEWaitForIE
If>res=sysSuccessNot
    Gosub>ErrIELoading,errIEWaitTimeout
Endif

// Get the window handle for use by MoveWindow and ResizeWindow
IEGetHWND>%currIE%,currIEHandle

// Move IE window to pos 10,10
// 1 means use and answer the window handle (NOT the title)
Let>WIN_USEHANDLE=1
MoveWindow>%currIEHandle%,1,1
Gosub>IEWaitForIE

// Resize IE window to 1100,1000
Let>WIN_USEHANDLE=1
ResizeWindow>%currIEHandle%,1100,1000
Gosub>IEWaitForIE

END>IECreateNew

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts