9

I know this is a very silly question. Yet, am not able to find how to make the browser open in fullscreen mode using watir webdriver. i tried using maximize() but in vain. This is how the code looks like:

require "rubygems"
require "watir-webdriver"
ff = Watir::Browser.new(:firefox)
ff.goto("http://google.com")
ff.maximize()

getting the error "undefined method maximize"

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Chandiran
  • 153
  • 1
  • 2
  • 7

7 Answers7

8

Right now, it's possible to maximize the browser doing:

require "rubygems"
require "watir-webdriver"
browser = Watir::Browser.new(:firefox)
browser.goto("http://google.com")    
browser.driver.manage.window.maximize

Actually is going down to Selenium Driver to handle it, and AFAIK it works fine in Firefox and Chrome.

Gonzalo
  • 193
  • 1
  • 3
  • 6
6

This worked for me! You have to say .window.maximize instead of just .maximize

browser = Watir::Browser.new "firefox" 
browser.goto "http://example.com"
browser.window.maximize
Aks..
  • 1,343
  • 1
  • 20
  • 42
4

what worked for me is the following

in hooks.rb (if you are using cucumber)

Before do
    @browser = Watir::Browser.new :firefox #( :chrome, :ie, etc)
    @browser.driver.manage.window.maximize
end
trickymuffin
  • 143
  • 2
  • 7
4

If you know screen size, you can move the browser to the top left corner and set it's size to screen size: Setting browser window size in Watir-webdriver.

Community
  • 1
  • 1
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • Thanks for replying. Trust me I posted this question only after seeing the post you've mentioned in your reply. And in fact, that is still there in the next tab of the browser :) I thought there would be some command like maximize() that would make the browser full mode – Chandiran Jul 14 '11 at 09:53
  • Y does this command **browser.execute_script('window.resizeTo(800,600)')** work in firefox but not in Chrome ? – Chandiran Jul 14 '11 at 10:09
  • Maybe there is, you should ask webdriver people. Add webdriver and/or selenium tag(s) to the question, or ask at their mailing list. – Željko Filipin Jul 14 '11 at 10:09
  • The browser (Chrome) is not getting resized to the size i mention. It stays in the default window size. No error message is displayed – Chandiran Jul 14 '11 at 10:15
  • could you pls provide ur feedback one this one too: [http://stackoverflow.com/questions/6176526/chrome-browser-opens-and-closes-using-watir-webdriver] – Chandiran Jul 14 '11 at 10:18
  • This is has been marked as WontFix in the Chromium tracker: http://code.google.com/p/chromium/issues/detail?id=2091 – jarib Jul 19 '11 at 20:43
  • I'm not sure if something changed, but I have absolutely no issues using `browser.window.resize_to 1400, 1040` in chrome. – Tyler MacMillan Nov 12 '14 at 15:22
4

I'm using ruby+watir-webdriver and this code works for both Firefox and IE browsers (I have not checked in other 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)
Stephen
  • 1,737
  • 2
  • 26
  • 37
Alexey Klimchuk
  • 129
  • 1
  • 1
1

I am not sure about the ruby code or watir, but for Chromedriver in selenium you cannot just call for the window to by maximized with the driver.manage().window().maximize();

Instead you have to do a neat little work around. You need to pass the option to the Chromedriver. See this post How to set Chrome preferences using Selenium Webdriver .NET binding?

var options = new ChromeOptions();
options.AddArgument("-start-maximized");
//start the chromedriver 
IWebDriver driver = new ChromeDriver(@"*Path_To_Chromedriver*", options)

   //Perform your test

driver.Quit(); 
Community
  • 1
  • 1
Ben
  • 667
  • 6
  • 13
  • The latest versions of ChromeDriver do support the driver.manage().window().maximize call. – Nathan Dace Feb 14 '14 at 21:15
  • Using ChromeDriver v2.9 (2014-01-31) that supports Chrome v31-34 and cannot make the call. – Ben Feb 14 '14 at 21:55
  • Try updating your WebDriver to the latest version, because it is certainly working. See https://code.google.com/p/chromedriver/issues/detail?id=65&can=1&q=maximize&colspec=ID%20Status%20Pri%20Owner%20Summary – Nathan Dace Feb 15 '14 at 14:25
-1

This worked for me

@browser = Watir::Browser.new
@browser.goto("http://google.com")
@browser.driver.manage().window().maximize
  • Note that this is the same as existing answers - eg the [answer by @gonzalo](http://stackoverflow.com/a/12412460/1200545) – Justin Ko Aug 09 '16 at 19:38