// Frames/iFrames driver.switchTo().frame("frameId"); // By ID/Name driver.switchTo().frame(0); // By index driver.switchTo().frame(driver.findElement(By.tagName("iframe"))); driver.switchTo().defaultContent(); // Back to main
Screenshots (Debug Gold!)
// Full page File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File("screenshot.png"));
// Element screenshot File elementShot = element.getScreenshotAs(OutputType.FILE);
Actions Class (Advanced Interactions)
Actions actions = new Actions(driver); actions.moveToElement(element).perform(); // Hover actions.contextClick(element).perform(); // Right-click actions.doubleClick(element).perform(); // Double-click actions.dragAndDrop(source, target).perform(); // Drag & drop
JavaScript Executor
JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollTo(0, 500);"); // Scroll js.executeScript("arguments[0].click();", element); // Force click String title = js.executeScript("return document.title;").toString();
Headless Mode (CI/CD)
ChromeOptions options = new ChromeOptions(); options.addArguments( "--headless=new", // New headless (2023+) "--window-size=1920,1080", "--disable-gpu", "--no-sandbox" ); WebDriver driver = new ChromeDriver(options);
TestNG Assertions
Assert.assertEquals(actual, expected, "Message"); // Equality Assert.assertTrue(condition, "Must be true"); // Condition Assert.assertFalse(condition, "Must be false"); // Negative Assert.assertNotNull(element, "Element required");
Common Exceptions & Fixes
Exception
Cause
Fix
NoSuchElement
Locator wrong
Verify selector in DevTools
StaleElement
DOM refresh
Re-locate after page change
Timeout
Element slow
Explicit Wait > Implicit
ElementNotInteractable
Hidden/Disabled
js.click() or scroll into view
Pro Tips for SDETs
Always use Explicit Waits over Thread.sleep()
Prefer CSS selectors over XPath (10x faster)
UseWebDriverManager – no manual driver downloads:javaWebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver();
Page Object Model – never use raw locators in tests
Screenshot on failure – TestNG @AfterMethod listener
Download Printable PDF: [Link to cheatsheet PDF]
Selenium WebDriver 2026 Cheat Sheet – Exhaustive
1. WebDriver Setup & Management
Action
Java Code
Notes
ChromeDriver
WebDriver driver = new ChromeDriver();
Auto-managed via Selenium Manager
FirefoxDriver
WebDriver driver = new FirefoxDriver();
GeckoDriver auto-download
EdgeDriver
WebDriver driver = new EdgeDriver();
Edge WebDriver
Headless Chrome
ChromeOptions ops = new ChromeOptions(); ops.addArguments("--headless=new");
He’s a builder of communities, a collector of questions, and a relentless challenger of assumptions. While others chase answers, he chases better questions. While others talk about the future of testing, he quietly helps create it.
Join the QABash community
Answer challenges, earn XP, grow your testing career.
What do you think about this article? Share your experience, ask a question, or add to the discussion.
Selenium
Selenium Grid 4: Architecture, Components, and Setup
Are you still struggling with outdated Selenium Grid 3 architecture while your competitors leverage Selenium…
10 min
AI Summary
Selenium 4.18+ with Chrome 122+ and WebDriverManager 5.6+ remains critical for legacy frameworks, offering auto-managed WebDriver setup, headless CI/CD options (`--headless --no-sandbox --disable-dev-shm-usage`), and robust navigation (`driver.navigate().to()`), while prioritizing explicit waits (`WebDriverWait`) over implicit waits or `Thread.sleep()`. Key features include CSS locators for speed, fluent waits with 30s timeout/2s polling, frame/window switching, screenshot capture via `Takes