Search code examples
seleniumselenium-webdriverbrowserresolutionscreen-resolution

How to check resolution of browser when running Selenium WebDriver


I want to check the resolution of browser when running Selenium WebDriver to change to expected resolution if ii is not correct. Is it possible to do that? Please give me some suggestion for this. Thanks.


Solution

  • None of the earlier answers actually answered the question (You asked how to get and set, rather than maximize or just set).

    I don't know what binding you are using, I'll show you Ruby binding as an example, my blog article also shows examples in other bindings.

    Full Ruby API doc is here. Java, C# or Python's API docs are here, here and here.

    Get the current window size:

    initial_size = driver.manage.window.size # type of Selenium::WebDriver::Dimension
    

    Set current window size:

    driver.manage.window.size = Selenium::WebDriver::Dimension.new(1024, 768)
    

    Resize current window:

    driver.manage.window.resize_to(800, 600)
    

    Maximize current window:

    driver.manage.window.maximize