Setting browser window size in Watir-webdriver
14,506
Solution 1
This works only for Firefox at the moment:
browser.window.resize_to(800, 600)
and you can move the browser, too:
browser.window.move_to(0, 0)
Solution 2
I'm using ruby+watir-webdriver and this code works for both FF and IE browsers (I have not checked in others browsers)
screen_width = browser.execute_script("return screen.width;")
screen_height = browser.execute_script("return screen.height;")
browser.driver.manage.window.resize_to(screen_width,screen_height)
browser.driver.manage.window.move_to(0,0)
Solution 3
I did something like this
browser = Watir::Browser.new :firefox, :profile => profile
browser.send_keys :f11
Author by
Alastair Montgomery
Seem to be the Jack of all programming trades these days, know a little bit of everything, enough to be dangerous anyway.
Updated on June 14, 2022Comments
-
Alastair Montgomery almost 2 years
How can you specify the size of the browser window opened when you call the following with watir-webdriver?
browser = Watir::Browser.new(:firefox)
-
Alastair Montgomery almost 13 yearsThanks will try it tomorrow :-)
-
adam reed almost 13 yearsThanks, this was the answer I didn't know I needed, too. It really helped with Jarmo's Win32Screenshot capability, too: Win32::Screenshot::Take.of(:desktop, :area => [0,0,1024,768])
-
Željko Filipin almost 13 years@adam: watir-webdriver has screen shots built in:
browser.driver.save_screenshot("file_name.png")
-
adam reed almost 13 yearsMake that two answers I didn't know I needed. I was experimenting with vanilla watir & Jarmo's library first before pulling it into the latest webdriver script - looks like I would be better-served with this one. Thanks!
-
Željko Filipin almost 13 yearsI'm glad I could help. More gems like these will soon be in my Watir book. watir.com/book :)
-
Boon almost 11 years@DavidWest Seems like a hack, but does the job ;).. thanks for the upvote mate :)
-
Martin almost 11 years@ŽeljkoFilipin When using
b.window.resize_to(400,400)
andb.driver.save_screenshot("screenshot.jpg")
the screenshot is not saved with the 400x400 and keep the original browser size. Any idea why? -
Željko Filipin almost 11 years@Martin: I will reply at stackoverflow.com/questions/17828277/…
-
Matt almost 10 years@ŽeljkoFilipin Is there a way to size the window proportionally to the screen or is that outside the scope of Watir? I'd like to have the browser take up half the screen.
-
Ripon Al Wasim over 9 yearsWhat about IE? How can I maximize IE browser?
-
HelloWorldNoMore about 8 years@ŽeljkoFilipin - Is Watir the same as Watir-Webdriver ? Thanks. PS - I don't want to make a question for this because it will be downvoted.
-
Michael about 7 yearsWorks for PhantomJS too! Thanks!