Maximize Browser in Selenium



We can maximize the browser in Selenium with the help of method maximize().

The present active window becomes maximized with this method.

Code implementation.

Example

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class BrowserMax {
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = "https://www.tutorialspoint.com/index.htm";
      driver.get(url);
      // maximizing browser with maximize()
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      driver.findElement(By.partialLinkText("Coding")).click();
      driver.close();
   }
}
Updated on: 2020-06-10T12:22:43+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements