I am running on Screen Resolution of (1366 X 768 ), but when I call getSize().getWidth()
and getSize().getHeight()
methods , the result I\'m gettin
As we know Selenium interacts with browsers and these get
methods will retrieve info related to browsers only. As explained in other answers very clearly, screen resolution and browser are different. The simple example below shows very clearly that the web driver is getting only the browser's dimensions.
WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");
System.out.println(driver.manage().window().getSize()); //output: (994, 718)
driver.manage().window().maximize();
System.out.println(driver.manage().window().getSize()); //output: (1382, 744)
For python selenium webdriver use function get_window_size:
driver.get_window_size()
"""
Output:
{
"width": 1255,
"height": 847,
"hCode": 939524096,
"class": "org.openqa.selenium.Dimension"
}
"""
The screen resolution and browser window size are not necessarily equal.
Resolution (from wikipedia) is
The display resolution or display modes of a digital television, computer monitor or display device is the number of distinct pixels in each dimension that can be displayed ... "1024 × 768" means the width is 1024 pixels and the height is 768 pixels
While getSize()
is returning the actual browser size.
Dimension initial_size = driver.manage().window().getSize();
int height = initial_size.getHeight();
int width = initial_size.getWidth();