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();
Selenium getsize() method

Set browser window size in selenium

Selenium has built in method to set size of browser window. You can use setSize() method to set the browser window size during your selenium test execution. This method is useful when you want to resize the browser window as per your selenium test requirement.
  • setSize() method is part of WebDriver.Window interface.
  • This method's return type is void.
  • You can provide the size of window to set set size of current working window in selenium test.
  • Syntax : driver.manage().window().setSize(new Dimension(w, h));
  • It will set window size as per the given dimension.
selenium setsize method

Full Screen Window In Selenium

Selenium fullscreen() method is used to full screen the browser window. It will perform browser full screen action same as real user full screen the browser window. May be sometimes you need full screen window in your selenium tests at that time this method will be very useful for you.

  • fullscreen() method is part of WebDriver.Window interface.
  • It's return type is void so it returns nothing.
  • It will full screen the browser window.
  • Syntax : driver.manage().window().fullscreen();
Below given example will show you how fullscreen() method is used to full screen the window size.

Selenium fullscreen method

Minimize window in selenium 

Selenium 4 has built in method to minimize the browser window. It is less used method in selenium but still you can use it if you want to minimize window in between selenium test. minimize() method will perform browser minimize user action. You can run your selenium tests in minimized browser mode and you can perform your other tasks beside.

  • minimize() method is part of WebDriver.Window method.
  • This method will return nothing because it's return type is void.
  • It will minimize the current working window if it is not already minimized.
  • It is helpful when your are performing manual testing or any other work as your selenium tests will be executed in minimized mode.
  • Syntax : driver.manage().window().maximize();

Selenium Minimize Window using minimize() method

Maximize window in selenium

You can maximize window in selenium using maximize() method. Every time you launch browser in selenium test, It will open browser window in small size. So maximize() is most commonly used method in selenium test scripts. Maximize() method works same as user click on browser maximize icon to maximize the window. Selenium test scripts can be run without maximizing windows as well but it is good practice to maximizing browser windows before running the tests on page.

selenium maximize() method

Get url in selenium using getCurrentUrl() Method

Sometimes you need to get the current url during selenium test. You can get the URL of current open page using getCurrentUrl() method in selenium.
  • getCurrentUrl() method is part of WebDriver interface which extends SearchContext interface.
  • It will fetch the url from current open page in browser.
  • It will return rul as a string.
  • Syntax to use getCurrentUrl() : driver.getCurrentUrl().
Below given example will show you how to get url of current open page using getCurrentUrl() method in selenium.
Selenium getCurrentUrl() Method

Close browser in selenium using close() method

To close browser in selenium, You can use close() method. It is used to close current open window on which selenium test is being executed.

  • close() method is part of WebDriver interface which extends SearchContext interface.
  • close() method in selenium will close only current selected window.
  • If multiple browser windows are open in selenium test then all windows will be not closed using close() method.
  • Syntax for using close() method is driver.close();
Selenium Close() Method

Selenium get title using getTitle() method

If you view source of page, You will find title of the page inside <title> and </title> tags. Selenium getTitle() method is useful to get the title of the page. You can verify or assert that title in selenium test case to check if targeted page is open or not.
  1. getTitle() method is part of WebDriver interface which extends SearchContext interface.
  2. It will return title of the web page if title is available for page.
  3. It will return null string if title of the page is missing.
  4. Syntax to get title : driver.getTitle();
Selenium getTitle() Method