Alastair Montgomery
Alastair Montgomery

Reputation: 1856

Setting browser window size in Watir-webdriver

How can you specify the size of the browser window opened when you call the following with watir-webdriver?

browser = Watir::Browser.new(:firefox)

Upvotes: 21

Views: 15077

Answers (3)

Boon
Boon

Reputation: 411

I did something like this

browser = Watir::Browser.new :firefox, :profile => profile
browser.send_keys :f11

Upvotes: 7

Alexey Klimchuk
Alexey Klimchuk

Reputation: 129

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)

Upvotes: 8

Željko Filipin
Željko Filipin

Reputation: 57262

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)

Upvotes: 33

Related Questions