Testing / Selenium Interview questions
How do you handle dynamic web elements in Selenium?
Because findElement resolves immediately rather than lazily, dynamic content generally needs an explicit wait for the right condition before interacting with it, rather than relying on a fixed pause.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement row = wait.until( ExpectedConditions.presenceOfElementLocated(By.cssSelector(".result-row")) );
For elements whose attributes change after an async update, ExpectedConditions.attributeToBe() or a custom lambda condition can wait for the specific state change rather than the element's mere presence. When a list re-renders entirely (common in single-page apps), re-fetching the locator fresh after the wait - rather than reusing a WebElement captured before the re-render - avoids a StaleElementReferenceException on the very next line.
More Related questions...