How can you specify the size of the browser window opened when you call the following with watir-webdriver?
browser = Watir::Browser.new(:firefox)
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.
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.
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)
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)
I did something like this
browser = Watir::Browser.new :firefox, :profile => profile
browser.send_keys :f11
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With