Skip to content

WebDevHubs

  • Home
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • Java
  • Selenium
  • PHP
  • Python
  • Programs
  • Toggle search form

Selenium WebDriver: Understanding the manage() Method in Java

Posted on July 20, 2025July 20, 2025 By Admin No Comments on Selenium WebDriver: Understanding the manage() Method in Java

The manage() method is a vital part of Selenium WebDriver’s API for Java, enabling automation scripts to control and configure various browser settings during runtime. This method returns a WebDriver.Options interface, which offers a suite of functionalities to manage windows, timeouts, cookies, and more.

What is the manage() Method?

  • Purpose: Grants access to the browser’s management options.
  • Returns: A WebDriver.Options object, from which you can further select sub-interfaces to manage windows, timeouts, cookies, etc.
  • Common Usage: Maximizing/minimizing windows, setting timeouts, handling cookies, and manipulating window positions.

Syntax:

driver.manage().window().maximize();

Here, driver is your active WebDriver instance.

Key Features and Usage

1. Window Management

Control browser window properties and behavior:

Maximize Window:

driver.manage().window().maximize();

Minimize Window:

driver.manage().window().minimize();

Full Screen:

driver.manage().window().fullscreen();

Set/Get Position:

driver.manage().window().setPosition(new Point(100, 200)); 
Point pos = driver.manage().window().getPosition();

2. Timeouts Management

Configure implicit waits and other timeouts to make automation more resilient:

Implicit Wait:

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); 

Sets the default wait time for locating elements.

Page Load Timeout:

driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));

Script Timeout:

driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(15));

3. Handling Cookies

Add, retrieve, and delete browser cookies:

Add Cookie:

Cookie cookie = new Cookie("username", "seleniumUser"); driver.manage().addCookie(cookie);

Get Cookie by Name:

Cookie myCookie = driver.manage().getCookieNamed("username");

Delete Cookie:

driver.manage().deleteCookieNamed("username");

Complete Code Example

Below is an end-to-end example demonstrating core uses:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.Point;
import java.time.Duration;

public class ManageExample {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
        WebDriver driver = new ChromeDriver();

        // Maximize window
        driver.manage().window().maximize();

        // Set timeouts
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

        // Add a cookie
        Cookie userCookie = new Cookie("testUser", "selenium");
        driver.manage().addCookie(userCookie);

        // Set window position
        driver.manage().window().setPosition(new Point(50, 50));

        driver.quit();
    }
}

Summary Table

ActionExample SyntaxDescription
Maximize windowdriver.manage().window().maximize();Enlarges the browser to full screen
Set Implicit Waitdriver.manage().timeouts().implicitlyWait(...);Sets default wait time for element discovery
Add Cookiedriver.manage().addCookie(new Cookie(...));Injects a cookie into the session
Set Positiondriver.manage().window().setPosition(new Point(...));Places the browser window at given coords

Best Practices

  • Always set necessary timeouts to avoid flaky tests, especially on dynamic web pages.
  • Use window controls to standardize browser appearance for screenshots or UI tests.
  • Cookie management can help with login flows or stateful testing.

The manage() method acts as a gateway for browser configuration and control in Selenium Java, making tests more stable and browsers more manageable.

Selenium Tags:Selenium-Java

Post navigation

Previous Post: Selenium WebDriver: Understanding the switchTo() Method in Java
Next Post: Selenium WebDriver: Understanding the navigate() Method in Java

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • CSS
  • HTML
  • Interview Experience
  • Java
  • JavaScript
  • Lodash
  • PHP
  • Programs
  • Python
  • Selenium
  • Software Testing
  • Web Technologies
  • Web Templates

Recent Posts

  • Java ArrayList trimToSize() Method
  • Java ArrayList toArray() Method
  • Java ArrayList subList() Method
  • Java ArrayList spliterator() Method
  • Java ArrayList sort() Method

Recent Comments

No comments to show.

Important Pages

  • About Us
  • Contact Us
  • Terms of Use
  • Privacy Policy

Web Development

  • HTML
  • CSS
  • JavaScript
  • PHP

Programming Languages

  • Java
  • Python
  • PHP
  • Programs

Others

  • Selenium
  • Lodash
  • Java ArrayList
  • JavaScript Array Methods

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme