We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
A comprehensive review of browser-level control, context switching, and advanced interactions.
In this unit, we moved beyond simple element interaction to controlling the browser itself. You learned how to navigate history, switch contexts (windows, frames, alerts), manage cookies, and use advanced tools like the Virtual Authenticator.
back(), forward(), refresh().setSize(), maximize() for responsive testing.addCookie(), deleteCookie() for session management.switchTo().alert() to accept/dismiss popups.switchTo().frame() to reach embedded content.switchTo().window() to handle tabs/popups.getScreenshotAs() for failure logs.print() for full-page reports.executeScript() for tricky interactions.1234567891011121314151617// 1. Manage Window & Cookies
driver.manage().window().maximize();
driver.manage().addCookie(new Cookie("session", "123"));
// 2. Navigate & Switch Contexts
driver.get("https://example.com");
driver.switchTo().frame("content-frame");
driver.findElement(By.id("btn")).click();
driver.switchTo().defaultContent();
// 3. Handle Alert
driver.switchTo().alert().accept();
// 4. Capture Evidence
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
driver.quit();Always know "where" Selenium is focused. If an element isn't found, check if you need to switch to a frame, window, or alert.
Use driver.quit() to close all windows and clear the session. Use removeVirtualAuthenticator() to detach keys.
Prefer native WebDriver commands over JS. Use JS only when necessary (e.g., scrolling stubborn elements).