Q1
Why does `StaleElementReferenceException` happen in modern React/Angular apps even right after element.isDisplayed()—and how do you fix it cleanly?
When React/Angular re-renders or re-hydrates a DOM container between finding WebElement and clicking it, the old DOM node pointer detaches. Never store stale WebElement references across async transitions; relocate dynamically via By locators inside WebDriverWait / ExpectedConditions.refreshed(...).
Q2
Why should you NEVER mix implicitlyWait and explicitWait (WebDriverWait) in the same Selenium session?
Selenium docs warn that mixing implicit + explicit waits causes unpredictable exponential wait spikes (e.g. ExpectedConditions.invisibilityOf waiting for an implicit 10s poll loop on *every* check cycle!). Keep implicitlyWait at 0 and rely purely on Explicit / Fluent Waits.
Q3
How do you automate elements buried inside a Shadow DOM (`#shadow-root (open)`) in Selenium 4 without failing NoSuchElementException?
Normal driver.findElement(By.xpath(...)) cannot pierce Shadow DOM boundaries! In Selenium 4, locate the host element then call host.getShadowRoot().findElement(By.cssSelector(...)) (note: only CSS selectors work inside Shadow Roots, never XPath!).
Q4
What is the difference between ElementClickInterceptedException vs ElementNotInteractableException, and why is JavascriptExecutor .click() a last resort?
Intercepted means a sticky navbar, modal backdrop, or toast physically covers the button; NotInteractable means it's hidden (display: none) or disabled. JavascriptExecutor bypasses real user visibility checks—hiding genuine UI overlap bugs from QA unless explicitly warranted.
Q5
Why can XPath expressions relying on contains(@class, 'btn') or full copied Chrome XPaths (div[3]/div[2]/span[1]) break every sprint?
Positional/absolute XPaths snap whenever a marketing banner shifts a div, and partial class matches collide across buttons. Prefer stable data-testid, semantic ARIA attributes, or anchored relative CSS/XPath (//label[text()='Email']/following::input[1]).
Q6
How do you handle iframe switching reliably so subsequent tests don't crash outside the frame?
Use wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameLocator)) and ALWAYS return with driver.switchTo().defaultContent() inside a try ... finally block (parentFrame() for nested frames).
Q7
Why does driver.close() vs driver.quit() matter at scale on Selenium Grid / CI?
driver.close() shuts only the active tab while leaving ChromeDriver orphan processes and Grid sessions alive consuming RAM until timeout! Always tear down cleanly with driver.quit().
Q8
How does Relative Locators in Selenium 4 (above, below, toRightOf, near) solve dynamic forms lacking IDs?
RelativeLocator.with(By.tagName('input')).below(By.id('emailLabel')) locates controls visually by layout relationship, remaining resilient to wrapper div changes.
Q9
Why does uploading files via <input type='file'> work far better with element.sendKeys('/abs/path') than OS Robot/AutoIT popups?
OS native dialogs freeze headless Linux Docker browsers completely (Robot fails without X11 display!). Calling sendKeys(absolutePath) directly on the <input type='file'> bypasses the OS picker cleanly on every OS and Grid node (with LocalFileDetector remotely).
Q10
How do you capture Browser Console Errors & Network 500 Responses automatically during Selenium 4 runs using BiDi / DevTools (CDP)?
Selenium 4 DevTools / BiDi listeners attach to Log and Network domains so tests automatically fail or attach logs whenever a frontend triggers uncaught JS exceptions or 500 API responses.