Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Current window Size using Selenium Webdriver?

I am running on Screen Resolution of (1366 X 768 ), but when I call getSize().getWidth() and getSize().getHeight() methods , the result I'm getting is:

Size of Width is : 1382 Size of Height is : 744

for IE, FF and Chrome web pages. URL used: https://www.google.com

like image 932
Nikhil Surendran Avatar asked Feb 29 '16 11:02

Nikhil Surendran


2 Answers

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)
like image 93
murali selenium Avatar answered Oct 21 '22 10:10

murali selenium


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"
}
"""
like image 29
Andriy Ivaneyko Avatar answered Oct 21 '22 08:10

Andriy Ivaneyko