QA Automation Cheatsheets
Instant syntax reference for Selenium WebDriver, Playwright, XPath, CSS Selectors, Waits, and Exception Handling. Copy-paste runnable code directly into your test suites.
Locators Cheatsheet
Complete reference for ID, Name, Class, CSS Selector, Relative XPath, and data-testid locator strategies. Includes Selenium and Playwright code syntax.
- ✓By.id vs By.cssSelector
- ✓data-testid best practices
- ✓Resilient selector hierarchy
- ✓Playwright getBy* methods
Selenium Commands
Browser control, navigation, window management, alert handling, dropdown selection with Select class, and Actions class mouse interactions.
- ✓driver.navigate() vs get()
- ✓Select dropdown handling
- ✓Actions hover and drag
- ✓Switching browser tabs
XPath & CSS Selectors
Side-by-side comparison of XPath vs CSS Selectors. Master text matching, contains(), starts-with(), axes (following, preceding, ancestor), and nth-child.
- ✓XPath axes navigation
- ✓CSS pseudo-classes
- ✓Text matching syntax
- ✓Performance comparisons
Waits & Synchronization
Never use Thread.sleep(). Learn Implicit Wait, Explicit Wait (WebDriverWait), FluentWait, and every ExpectedConditions method for rock-solid tests.
- ✓WebDriverWait patterns
- ✓elementToBeClickable()
- ✓visibilityOfElementLocated()
- ✓Custom FluentWait polling
Common Automation Errors
Diagnose and fix StaleElementReferenceException, NoSuchElementException, ElementClickInterceptedException, and TimeoutException with proven recipes.
- ✓Stale element retry patterns
- ✓Click intercepted bypasses
- ✓JavaScript click fallback
- ✓Dynamic ID handling
Most Frequently Used Locators at a Glance
Keep these production-tested patterns handy when automating our 10 practice portals.
//button[text()='Login']//div[contains(text(), 'Welcome')]button[data-testid='submit-btn']wait.until(ExpectedConditions.elementToBeClickable(By.id('otp')));Frequently Asked Questions
Should I prefer CSS Selectors or XPath for web automation?
Prefer CSS Selectors for simple class, ID, and attribute matching because browsers evaluate CSS natively faster. Use XPath when you need to navigate up the DOM tree (parent/ancestor navigation) or locate elements by exact inner text, as standard CSS cannot search text content or traverse upward.
What is the locator priority hierarchy recommended for reliable tests?
The industry standard priority is: (1) data-testid or dedicated test attributes, (2) unique semantic ID, (3) name attribute, (4) specific CSS selector, (5) relative XPath with robust attributes, and never use absolute XPath (e.g. /html/body/div[2]/div/span) as it breaks with the slightest layout change.
Why does StaleElementReferenceException occur and how do I prevent it?
It happens when a WebElement was located on the page, but subsequent JavaScript execution, AJAX refresh, or DOM re-rendering detached that element from the active document tree. Fix it by re-locating the element immediately before interacting, or using WebDriverWait with ExpectedConditions.refreshed().