Testing / Selenium Interview questions
What is a WebElement in Selenium?
A WebElement is Selenium's representation of a single DOM node, returned by findElement(), and it's the object interactions like .click(), .sendKeys(), and .getText() are called on.
WebElement email = driver.findElement(By.id("email")); email.sendKeys("user@example.com"); System.out.println(email.getText());
Because a WebElement reference is tied to a specific DOM node at the moment it was found, it becomes invalid - throwing StaleElementReferenceException - if that part of the DOM is replaced or removed afterward, even if a visually identical element reappears. This is a key behavioral difference from frameworks with lazy, auto-re-resolving locators.
More Related questions...