// 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)
Useย WebDriverManagerย – 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");
Captain Jarhead is a fearless Java expert with a mission to conquer bugs, optimize code, and brew the perfect Java app. Armed with a JVM and an endless supply of caffeine, Captain Jarhead navigates the wild seas of code, taming exceptions and turning null pointers into smooth sailing. A true master of beans, loops, and classes, Captain Jarhead ensures no bug escapes his radar!
AWS IAM Crisis: 90% Misconfigs Threaten QA PipelinesโFix Now
Your test pipeline haltsโIAM role denied. CloudTrail floods with failed RDS auth attempts. 90% of AWS accounts have IAM misconfigurations risking data breaches. QA...
AWS IAM Crisis: 90% Misconfigs Threaten QA PipelinesโFix Now
Your test pipeline haltsโIAM role denied. CloudTrail floods with failed RDS auth attempts. 90% of AWS...