Is there a way to maximize the browser window using WebDriver (Selenium 2)?
+3
A:
There's an outstanding issue to add this functionality to WebDriver, which can be tracked here: http://code.google.com/p/selenium/issues/detail?id=174
A workaround would be to use the JavascriptExector
as follows:
public void resizeTest() {
driver.Navigate().GoToUrl("http://www.example.com/");
((IJavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768);");
}
Dave Hunt
2010-07-07 08:34:33
Two things: 1) If you care what's visible you probably want to move the window to origin before making it full screen.2) If the screen dimensions are variable you can get them at run time with the javascript `screen` object.Taking these points into consideration the javascript should probably be:`window.moveTo(0,0); window.resizeTo(screen.width, screen.height);`
Guildencrantz
2010-07-08 01:30:48
Note that there's an issue moving the window to (0,0) in Firefox on Mac. It appears to not account for its header region properly. Moving the window to (0,1) seems to actually move it to (0,0) though, so one bug helps another. At that point you can maximize the window properly.
nirvdrum
2010-08-12 11:58:57
+1
A:
You can use Selenium Emulation in WebDriver:
selenium = new WebDriverBackedSelenium(driver,url);
selenium.windowMaximize();
ZloiAdun
2010-07-14 19:29:59
They don't have Selenium Emulation in the C# version of webdriver. At least not yet in 2.0a4 (just saw they released a new version haven't checked it out yet though). However the above javascript code works great.
Reflux
2010-07-16 18:55:18
A:
There is a function that you can use to maximize the window in Python which is window_maximize(). And this is how I'm using it.Hope this helps -
from selenium import selenium
sel = selenium('localhost', 4444, '*firefox', 'http://10.77.21.67/')
sel.start()
sel.open('/')
sel.wait_for_page_to_load(60000)
#sel.window_focus()
sel.window_maximize()
png = sel.capture_screenshot_to_string()
f = open('screenshot.png', 'wb')
f.write(png.decode('base64'))
f.close()
sel.stop()
fixxxer
2010-09-03 15:31:44