Testing / Selenium Interview questions
What are locators in Selenium?
Locators are the strategies Selenium uses to find a specific element on a page so an action or check can be performed on it, exposed through the By class.
driver.findElement(By.id("username")); driver.findElement(By.name("email")); driver.findElement(By.cssSelector(".btn-primary")); driver.findElement(By.xpath("//button[text()='Submit']"));
Available strategies include id, name, className, tagName, linkText, partialLinkText, cssSelector, and xpath. Unlike Playwright's lazy locators, a Selenium WebElement returned by findElement is resolved immediately against the current DOM and does not automatically re-query later, which is why it can become stale if the page re-renders after it was found.
More Related questions...