3

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.

2
  • Why do you need to do this? What are you actually intending to do? Are you just trying to maximise the window if it isn't already? Commented Jul 16, 2013 at 14:03
  • Because I run the selenium webdriver on computers that has different resolution (1920x1080 and 1680x1050) to capture and verify the screenshot of web page. When I capture image on 1680x1050 monitor it will different from the image when capturing on 1920x1080. So I need to check the resolution of browser after maximizing it to resize browser to 1680x1050 if computer has other kind of resolution. Commented Jul 17, 2013 at 2:28

3 Answers 3

8

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you so much. It is the answer for my case.
3

using python bindings you can set the resolution like this

driver = webdriver.Firefox()
driver.get("http://www.google.com")
# Resize the window to the screen width/height
driver.set_window_size(300, 500)

Comments

0

Try this,

driver.manage().window().maximize();

for more info http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.RemoteWebDriverOptions.RemoteWindow.html#maximize

Hope it will help you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.