4

I am writing a script that opens internet explorer using the webbrowser module and the .open function. By default, on my system, this opens IE in full-screen view. Is there a way to specify the size/location (width, height, x, y) of the browser window that will be opened?

Example: I want to open an IE window @ a specific URL (ie Google Maps) and have the window be located in the bottom-right portion of my screen.

Like I said, I'm currently using webbrowser.open to open the Google Maps page in IE, but I am open to any other method of doing this that would allow me to specify the size/location of the IE window when opened.

--Thanks

Aksparks04
  • 41
  • 1
  • 2
  • Do you have access to edit this webpage? – jonathan.hepp Nov 21 '11 at 19:18
  • related: [set size/position of browser window using `selenium.webdriver`](http://stackoverflow.com/questions/8075297/how-to-maximize-a-browser-window-using-the-python-bindings-for-selenium-2-webdri/8076288#8076288), but it probably doesn't suit your use case. – jfs Nov 21 '11 at 19:40
  • @dex18dt -- no. I want to open IE at the Google Maps page, but I want the IE app window to not be fullscreen and be sized a certain way in the bottom right of my screen. I dont want to mod the actual site. Sorry, maybe I wasnt clear. – Aksparks04 Nov 21 '11 at 23:45
  • @J.F. Sebastian -- no offense, but why do people always question posters as to why they need a certain functionality. I am working on automating a suite of manual tests on a device's UI. I have a test that opens 3 windows at once and I would like them to be laid out on my monitor in a certain fashion so that the tester can see all of them at once and I don't want one window overlaying another so that the tester cannot interact with a needed window. That enough info? :P – Aksparks04 Nov 21 '11 at 23:48
  • @Aksparks04: I should have ask: "please, elaborate in what particular context you'd like to use it" instead of "why do you need this?". The answer to such questions may help to answer *your question*. For example, in principle `selenium.webdriver` can help to automate a suite of manual tests but it is not an exact match for your case based on the info you provided. It might help if you [put your comment in the question](http://stackoverflow.com/posts/8217221/edit) so more people could see it. – jfs Nov 22 '11 at 01:11

3 Answers3

1

i took some code from another post on here that basically is using the windows api to control the mouse ( you need the pywin module)

def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Doing some more digging, i found how to find the mouse position. This tiny script gets the mouse x,y

import win32api, win32con
import win32gui
x, y = win32api.GetCursorPos()
print '[*] X coordinate:   %s\n[*] Y coordinate:   %s'%(x,y)

So then all you do is hold your mouse over the maximize icon when firefox is first opened, alt tab to your cmd.exe and run the script ( in my case, up arrow, enter)

so once you have that you can just

webbrowser.open_new('http://google.com')
click(x,y)

its not exactly what you wanted, but maybe you can do some click-drag and resize? youll have to look

user1734291
  • 7
  • 1
  • 2
  • 6
1

You can use webview:

import webview

window = webview.create_window("your custom title for th window", 'https://www.website.com') 
webview.start()

you can customize the size of the window all you want:

webview.create_window(title, url='', html='', js_api=None, width=800, height=600,
                      x=None, y=None, resizable=True, fullscreen=False, \
                      min_size=(200, 100), hidden=False, frameless=False, \
                      minimized=False, confirm_close=False, background_color='#FFF', \
                      text_select=False)

although you have to call it in the main thread. Here's the docs: https://pywebview.flowrl.com/blog/pywebview3.html

Adam
  • 123
  • 10
0

The only way I see this may be possible is if this webpage has an HTML anchor (#) on the desired position or if you actually have access to edit the webpage to insert that anchor. The webbrowser module doesn't have much functions and parameters to access the system's browser. In case the anchor exists you can simply direct the link to it, like:

mylink = "http://www.mysite.com/mywebpage.html#myanchor"
webbrowser.open_new(mylink)
jonathan.hepp
  • 1,603
  • 3
  • 15
  • 21