https://practicetestautomation.com/practice-test-login/
Comparison Differnt Versions of Selenium#
1
2
3
4
5
6
7
8
9
10
11
12
| // Selenium 2, 3 (Manual driver setup)
System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Selenium 4.0 – 4.5 (Using external WebDriverManager)
import io.github.bonigarcia.wdm.WebDriverManager;
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
// Selenium 4.6+ to 4.38 (Built-in Selenium Manager — current)
WebDriver driver = new ChromeDriver(); // No setup needed
|
Best Practices#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| // Window management
driver.manage().window().maximize();
// Cookies
driver.get("https://www.google.com");
driver.manage().addCookie(new Cookie("TestCookie", "12345"));
// Timeouts — Best Practice
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); // for element search
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(20)); // for full page load
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(10)); // for JS scripts
// Example: delete old cookies at start
driver.manage().deleteAllCookies();
|
driver.manage() – Overview#
| Category | Common Methods | Purpose |
|---|
| Window | maximize(), minimize(), fullscreen(), setSize(), setPosition() | Control browser window |
| Cookies | getCookies(), addCookie(), deleteAllCookies() | Manage session cookies |
| Timeouts | implicitlyWait(), pageLoadTimeout(), scriptTimeout() | Control how Selenium waits for operations |
Timeouts — driver.manage().timeouts()#
| Method | Description |
|---|
implicitlyWait(Duration time) | Wait for elements to appear |
pageLoadTimeout(Duration time) | Max time to wait for page to load |
scriptTimeout(Duration time) | Max time for asynchronous scripts (JS) |
Sample Test Case#
You are a Selenium Java expert.
I need to automate a simple task: