Skip to content

Instantly share code, notes, and snippets.

@mnmldave
Created December 12, 2011 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnmldave/1463847 to your computer and use it in GitHub Desktop.
Save mnmldave/1463847 to your computer and use it in GitHub Desktop.
Resize browser windows with Selenium WebDriver in Ruby
driver = WebDriver.for(:remote, :url => Helper.grid, :desired_capabilities => caps)
width = 1024
height = 768
# Resize window. In Firefox and Chrome, must create a new window to do this.
# http://groups.google.com/group/webdriver/browse_thread/thread/e4e987eeedfdb586
case driver.capabilities[:browser_name]
when 'firefox', 'chrome'
handles = driver.window_handles
driver.execute_script("window.open('about:blank','_blank','width=#{width},height=#{height}');")
driver.switch_to.window((driver.window_handles - handles).pop)
driver.execute_script("window.resizeTo(#{width}, #{height}); window.moveTo(0,1);")
else
driver.execute_script("window.resizeTo(#{width}, #{height}); window.moveTo(0,1);")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment