Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.