Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 448
Alastair Montgomery Avatar asked May 25 '11 14:05

Alastair Montgomery


People also ask

How do I change the size of my browser in Selenium?

You need to use resize method to minimize the browser. void setSize() – This method is used to set the size of the current browser. Dimension getSize() – This method is used to get the size of the browser in height and width. It returns the dimension of the browser.

How do I change the width and height of my browser?

We can also set the browser width and height with the help of Chrome options. We have to create an object of the ChromeOptions class and apply addArguments to it. The parameter window-size set with values of height and width of the browser are passed as arguments to the method.


3 Answers

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)
like image 77
Željko Filipin Avatar answered Oct 17 '22 14:10

Željko Filipin


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)
like image 8
Alexey Klimchuk Avatar answered Oct 17 '22 15:10

Alexey Klimchuk


I did something like this

browser = Watir::Browser.new :firefox, :profile => profile
browser.send_keys :f11
like image 7
Boon Avatar answered Oct 17 '22 14:10

Boon