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.
-
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?Arran– Arran2013-07-16 14:03:52 +00:00Commented 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.Popo– Popo2013-07-17 02:28:20 +00:00Commented Jul 17, 2013 at 2:28
Add a comment
|
3 Answers
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
1 Comment
Popo
Thanks you so much. It is the answer for my case.
Try this,
driver.manage().window().maximize();
Hope it will help you.