Opening a browser in fullscreen mode using watir-webdriver
Asked Answered
M

7

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"

Miksen answered 14/7, 2011 at 9:7 Comment(0)
E
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.

Enhance answered 14/7, 2011 at 9:23 Comment(7)
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 modeMiksen
Y does this command browser.execute_script('window.resizeTo(800,600)') work in firefox but not in Chrome ?Miksen
Maybe there is, you should ask webdriver people. Add webdriver and/or selenium tag(s) to the question, or ask at their mailing list.Receive
The browser (Chrome) is not getting resized to the size i mention. It stays in the default window size. No error message is displayedMiksen
could you pls provide ur feedback one this one too: [#6177026Miksen
This is has been marked as WontFix in the Chromium tracker: code.google.com/p/chromium/issues/detail?id=2091Candancecandela
I'm not sure if something changed, but I have absolutely no issues using browser.window.resize_to 1400, 1040 in chrome.Patrizia
D
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.

Denton answered 13/9, 2012 at 18:23 Comment(0)
A
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
Adila answered 25/7, 2014 at 6:49 Comment(0)
E
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.

Enhance answered 14/7, 2011 at 9:23 Comment(7)
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 modeMiksen
Y does this command browser.execute_script('window.resizeTo(800,600)') work in firefox but not in Chrome ?Miksen
Maybe there is, you should ask webdriver people. Add webdriver and/or selenium tag(s) to the question, or ask at their mailing list.Receive
The browser (Chrome) is not getting resized to the size i mention. It stays in the default window size. No error message is displayedMiksen
could you pls provide ur feedback one this one too: [#6177026Miksen
This is has been marked as WontFix in the Chromium tracker: code.google.com/p/chromium/issues/detail?id=2091Candancecandela
I'm not sure if something changed, but I have absolutely no issues using browser.window.resize_to 1400, 1040 in chrome.Patrizia
S
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)
Sox answered 24/1, 2012 at 12:1 Comment(1)
For chrome, this is the only solution working for me on macRafa
B
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
Baziotes answered 9/5, 2014 at 19:57 Comment(0)
W
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(); 
Wholism answered 14/2, 2014 at 18:46 Comment(3)
The latest versions of ChromeDriver do support the driver.manage().window().maximize call.Blurt
Using ChromeDriver v2.9 (2014-01-31) that supports Chrome v31-34 and cannot make the call.Wholism
Try updating your WebDriver to the latest version, because it is certainly working. See code.google.com/p/chromedriver/issues/…Blurt
N
-1

This worked for me

@browser = Watir::Browser.new
@browser.goto("http://google.com")
@browser.driver.manage().window().maximize
Neurophysiology answered 9/8, 2016 at 19:8 Comment(1)
Note that this is the same as existing answers - eg the answer by @gonzaloDelacruz

© 2022 - 2024 — McMap. All rights reserved.