How do I set browser width and height in Selenium WebDriver?
Here is how I do it in Python with Selenium 2.48.0:
from selenium.webdriver import Firefox
driver = Firefox()
driver.set_window_position(0, 0)
driver.set_window_size(1024, 768)
For me, the only thing that worked in Java 7 on OS X 10.9 was this:
// driver = new RemoteWebDriver(new URL(grid), capability);
driver.manage().window().setPosition(new Point(0,0));
driver.manage().window().setSize(new Dimension(1024,768));
Where 1024
is the width, and 768
is the height.
Here's a solution that works with both headless and non-headless mode and will start the window with the specified size instead of setting it after:
Chrome:
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument("--window-size=2560,1440")
driver = Chrome(options=opts)
Firefox:
from selenium.webdriver import Firefox, FirefoxOptions
opts = FirefoxOptions()
opts.add_argument("--width=2560")
opts.add_argument("--height=1440")
driver = Firefox(options=opts)
Try something like this:
IWebDriver _driver = new FirefoxDriver();
_driver.Manage().Window.Position = new Point(0, 0);
_driver.Manage().Window.Size = new Size(1024, 768);
Not sure if it'll resize after being launched though, so maybe it's not what you want
If you are using chrome
chrome_options = Options()
chrome_options.add_argument("--start-maximized");
chrome_options.add_argument("--window-position=1367,0");
if mobile_emulation :
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
self.driver = webdriver.Chrome('/path/to/chromedriver',
chrome_options = chrome_options)
This will result in the browser starting up on the second monitor without any annoying flicker or movements across the screen.