Resize Chrome's window while using Capybara Resize Chrome's window while using Capybara selenium selenium

Resize Chrome's window while using Capybara


There is resize_to function in Selenium Webdriver that you can use:

page.driver.browser.manage.window.resize_to(1024, 768)

Window has some other methods that may be useful.


I've found that the Driver#browser call is now deprecated (Capybara 2.5.0).

You can use the Driver#resize_window_to call to resize the window:

page.driver.resize_window_to(page.driver.current_window_handle, 1_200, 800)

You can also use Session#current_window then Window#resize_to:

page.current_window.resize_to(1_200, 800)

Look at the docs for more info:

http://www.rubydoc.info/github/jnicklas/capybara/Capybara


Late answer but someone may need this. You can initiate chromedriver by giving windows size so that you don't need to size it after loading the page:

Capybara.register_driver :chrome_sizes do |app|  profile = Selenium::WebDriver::Chrome::Profile.new   Capybara::Selenium::Driver.new(app,    :browser => :chrome,    :profile => profile,    :args => ["--window-size=1240,1400"]  )end