Loading ...

Selenium Interview Questions 2025

Selenium is the world’s leading open-source tool for web automation testing. Whether you are a beginner or an experienced tester, cracking Selenium interviews requires understanding locators, WebDriver, waits, POM, Selenium Grid, and real-world testing scenarios.


1. What is Selenium?

Selenium is an open-source automation tool used to test web applications across browsers and platforms.

Components:

  • Selenium IDE – Record & playback tool

  • Selenium WebDriver – Browser automation API

  • Selenium Grid – Parallel test execution

  • Selenium RC – Legacy tool (deprecated)


2. Selenium Locators

Locators identify web elements.

Types: ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, CSS Selector, XPath

Example:

WebElement username = driver.findElement(By.id("username")); username.sendKeys("admin");

3. driver.close() vs driver.quit()

MethodAction
driver.close()Closes current browser window
driver.quit()Closes all windows and ends session

4. Handling Checkboxes

WebElement checkbox = driver.findElement(By.id("subscribe")); if(!checkbox.isSelected()){ checkbox.click(); }

5. Handling Dropdowns

Select dropdown = new Select(driver.findElement(By.id("options"))); dropdown.selectByVisibleText("Option 1"); dropdown.selectByValue("1"); dropdown.selectByIndex(0);

6. findElement() vs findElements()

  • findElement() β†’ Returns first element, throws exception if not found

  • findElements() β†’ Returns list, empty if none found


7. Opening a Webpage

driver.get("https://example.com"); driver.navigate().to("https://example.com");

8. Selenium WebDriver

WebDriver automates browsers directly without a server.

WebDriver driver = new ChromeDriver(); driver.get("https://example.com");

9. Absolute vs Relative XPath

XPathExample
Absolute/html/body/div[1]/input
Relative//input[@id='username']

10. Mouse Actions

Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform(); actions.contextClick(element).perform(); actions.doubleClick(element).perform();

Medium Questions (11–20) <a name="medium-questions"></a>

11. Selenium Waits

  • Implicit Wait: Global wait

  • Explicit Wait: Wait for specific condition

  • Fluent Wait: Polling frequency and exceptions

WebDriverWait wait = new WebDriverWait(driver, 10); WebElement loginBtn = wait.until(ExpectedConditions.elementToBeClickable(By.id("login"))); loginBtn.click();

12. Handling Alerts

Alert alert = driver.switchTo().alert(); alert.accept(); alert.dismiss(); alert.getText();

13. Multiple Windows

String mainWindow = driver.getWindowHandle(); Set<String> windows = driver.getWindowHandles(); for(String win : windows){ driver.switchTo().window(win); }

14. Handling Frames

driver.switchTo().frame("frameName"); driver.switchTo().defaultContent();

15. Keyboard Actions

Actions actions = new Actions(driver); actions.sendKeys(Keys.ENTER).perform(); actions.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();

16. Screenshots

File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("screenshot.png"));

17. Scrolling Using JS

JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0,500)"); js.executeScript("arguments[0].scrollIntoView();", element);

18. Page Object Model (POM)

public class LoginPage { WebDriver driver; By username = By.id("username"); By password = By.id("password"); public void login(String user, String pass){ driver.findElement(username).sendKeys(user); driver.findElement(password).sendKeys(pass); } }

19. Dynamic Elements

driver.findElement(By.xpath("//input[contains(@id,'user')]"));

20. Selenium Grid

  • Parallel execution across browsers and OS

  • Reduces total execution time

Diagram suggestion: Grid hub + nodes layout


Hard Questions (21–30) <a name="hard-questions"></a>

21. AJAX Elements

WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ajaxElement")));

22. File Upload

driver.findElement(By.id("fileUpload")).sendKeys("C:\\path\\file.txt");

23. Headless Mode

ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); WebDriver driver = new ChromeDriver(options);

24. SSL Certificate Handling

ChromeOptions options = new ChromeOptions(); options.setAcceptInsecureCerts(true); WebDriver driver = new ChromeDriver(options);

25. Console Logs

LogEntries logs = driver.manage().logs().get(LogType.BROWSER); for(LogEntry entry : logs){ System.out.println(entry.getMessage()); }

26. Drag & Drop

Actions actions = new Actions(driver); actions.dragAndDrop(sourceElement, targetElement).perform();

27. Dynamic Tables

List<WebElement> rows = driver.findElements(By.xpath("//table/tbody/tr")); for(WebElement row : rows){ System.out.println(row.getText()); }

28. Assert vs Verify

  • assert β†’ Stops test execution if fails

  • verify β†’ Logs failure, continues execution


29. Selenium Limitations

  • Cannot automate desktop applications

  • Limited support for Captcha & images

  • No built-in reporting


30. Integration with TestNG/JUnit

@Test public void loginTest(){ driver.get("https://example.com"); }

  • TestNG annotations: @Test, @BeforeMethod, @AfterMethod

  • Enables parallel execution and detailed reports

✍️ By Not available | 2025-10-21T09:08:23.979Z

Call Our Course Advisors

IND: +91-98018 30173 / +91-70429 28331

US: +1-252 490 1033

UK: +44-121 3871751