Selenium getSize() method
You can get the browser window size using getSize() method in selenium. It will be helpful to get the current working window size(height & width) in selenium test execution if required.
- getSize() method in selenium is part of WebDriver.Window interface.
- It is used when you want to get current working window dimensions.
- It will return height and width of current working browser window.
- Syntax : driver.manage().window().getSize();
Let us see how getSize() method works to get browser window dimension with example.
Selenium getSize() method example to get window size
package testPackage;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class getsizeExample{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
//Get current window size dimension and print it in console.
Dimension size = driver.manage().window().getSize();
System.out.println(size);
}
}
In above given example, getsize() method will return height and width of current launched window and it will print it in console.
No comments:
Post a Comment