Top 20 Selenium Interview Questions & Answers

Prepare for your Selenium automation interview with these carefully curated questions covering basic to advanced concepts.

Table of Contents

  1. Basic Selenium Questions

  2. Actions Class Questions

  3. Locators Questions

  4. Window/Frames Handling

  5. Advanced Concepts

  6. Framework & OOPS


1. Basic Selenium Questions

Q1: How to launch different browsers?

java

// Chrome
WebDriver driver = new ChromeDriver();

// Firefox
WebDriver driver = new FirefoxDriver();

// Edge
WebDriver driver = new EdgeDriver();

Q2: Difference between get() and navigate().to()

  • get(): Loads a new page and waits for completion

  • navigate().to(): Does the same but maintains browser history

Q3: Navigation commands

java

driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();

Q4: close() vs quit()

  • close(): Closes current window

  • quit(): Closes all windows and ends session

Q5: Handling dropdowns

java

Select select = new Select(driver.findElement(By.id("dropdown")));
select.selectByVisibleText("Option");

2. Actions Class Questions

Q6: Mouse hover implementation

java

Actions actions = new Actions(driver);
actions.moveToElement(element).perform();

Q7: Drag and drop

java

actions.dragAndDrop(source, target).perform();

Q8: Right-click and double-click

java

actions.contextClick(element).perform();  // Right-click
actions.doubleClick(element).perform();  // Double-click

3. Locators Questions

Q9: Locator types

8 types: ID, Name, ClassName, TagName, LinkText, PartialLinkText, CSS, XPath

Q10: findElement() vs findElements()

  • findElement(): Returns first matching element

  • findElements(): Returns list of all matching elements

Q11: XPath types

  • Absolute: /html/body/div

  • Relative: //div[@class='example']


4. Window/Frames Handling

Q12: Switching windows

java

for (String handle : driver.getWindowHandles()) {
    driver.switchTo().window(handle);
}

Q13: Handling iframes

java

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

5. Advanced Concepts

Q14: Handling dynamic elements

Use Explicit Waits:

java

new WebDriverWait(driver, 10)
    .until(ExpectedConditions.visibilityOfElementLocated(By.id("dynamic")));

Q15: Taking screenshots

java

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

Q16: Handling file uploads

java

driver.findElement(By.id("upload")).sendKeys("file_path");

6. Framework & OOPS

Q17: Common framework types

  • Data-Driven

  • Keyword-Driven

  • Hybrid

  • POM (Page Object Model)

Q18: OOPS in Selenium

Key concepts:

  • Encapsulation (Page Objects)

  • Inheritance (BaseTest classes)

  • Polymorphism (Method overloading)

Q19: CI/CD Integration

Popular tools:

  • Jenkins

  • GitHub Actions

  • Azure DevOps

Q20: How to handle Captcha?

Captcha can't be handled with Selenium. CAPTCHAs are specifically designed to prevent automated interactions. The dev team can be asked to disable it on Dev/QA environments.


Pro Tip: Focus on practical implementation rather than theoretical definitions during interviews.

    Popular posts from this blog

    Real-World Examples and Demo Scripts in Selenium Python Automation

    Top 10 Demo Websites for Selenium Automation Practice

    Selenium IDE Tutorial: A Beginner's Guide to No-Code Automation Testing

    Behavior-Driven Development (BDD) with Python Behave: A Complete Tutorial

    25+ Selenium WebDriver Commands: The Complete Cheat Sheet with Examples

    Mastering Selenium Practice: Automating Web Tables with Demo Examples

    Top 10 Highest Paid Indian-Origin CEOs in the USA

    Selenium Automation for E-commerce Websites

    A Complete Guide to API Development

    My 4-Week Journey to Mastering Selenium WebDriver