TestingTestingintermediate

Selenium Interview Questions and Answers

25 Selenium WebDriver questions with Java code, from first-round basics to framework design for 3, 4, 5 and 7 years of experience.

Published
TL;DR – Quick Answer

Selenium interviews test WebDriver basics, locators, waits, windows, frames, TestNG and the Page Object Model. Experienced candidates also face framework design, parallel runs, Grid, CI and flaky tests. The strongest answers explain why a test fails and how you made it reliable.

On This Page

Selenium interview questions start with locators and waits, then move to the framework you built and the failures you fixed. This page has 25 questions with Selenium 4 and Java answers. It covers freshers as well as candidates with 3, 4, 5 and 7 years of experience.

Code here shows the useful part of a test. It assumes Selenium and TestNG are in your project and driver is a WebDriver object. The snippets are for reading and adapting, so imports and output are left out.

How Selenium interview questions change by level

Experience What to prepare
Fresher WebDriver, locators, waits, simple test
3 years Page objects, TestNG, common exceptions
4 years Data-driven tests, CI and parallel runs
5 years Framework choices and flaky tests
7 years Strategy, cost, people and test balance

Pro tip: For any problem, say what you saw, why it happened, what you changed and how you checked the fix.

Selenium questions for freshers

Q1. What is Selenium?

30-second answer: Selenium is an open-source project for automating web browsers. WebDriver controls browsers, Grid runs sessions on other machines, and IDE records simple browser actions.

Selenium does not decide whether a test passed. Your code and a runner such as TestNG do that.

Q2. How does WebDriver communicate with the browser?

30-second answer: In classic WebDriver, test code sends W3C WebDriver commands over HTTP to a browser driver. The driver controls the browser and returns a response.

Selenium 4 also supports parts of WebDriver BiDi, where the browser can send events back.

Q3. Do you need to download ChromeDriver manually?

30-second answer: Usually not with current Selenium 4. Selenium Manager, included since version 4.6, can find or download a suitable driver when one is not already set up.

WebDriver driver = new ChromeDriver();
try {
    driver.get("https://example.com");
    System.out.println(driver.getTitle());
} finally {
    driver.quit();
}

The finally block closes the browser even if a step fails. A company network may block downloads, so teams may still provide drivers themselves.

Q4. Which locators does Selenium support?

30-second answer: The main ones are id, name, class name, tag name, link text, partial link text, CSS selector and XPath. Selenium 4 also adds relative locators, which find an element near another one.

I prefer a stable, unique id or test attribute. Long paths based on page layout break easily.

Q5. What is the difference between CSS and XPath?

30-second answer: CSS selectors are usually shorter. XPath can move up to a parent and find visible text, which Selenium CSS selectors cannot do in the same way.

By saveButton = By.cssSelector("button[data-test='save']");
By ashaRow = By.xpath("//td[text()='Asha']/parent::tr");

Choose the clearer and steadier one. Do not claim that one is always faster.

Q6. What is the difference between close and quit?

30-second answer: close() closes the current window. quit() ends the whole browser session and closes all its windows.

Run quit() in teardown so that it happens even when a test fails. Otherwise, browsers left open can use up memory on the test machine.

Q7. What is the difference between findElement and findElements?

30-second answer: findElement returns the first match or throws NoSuchElementException. findElements returns a list, which is empty when there is no match.

Use findElements(...).isEmpty() when absence is a normal result. Remember that an implicit wait can make this check wait before it returns an empty list.

Q8. How do you handle a dropdown?

30-second answer: For an HTML select element, I use the Select class. For a custom dropdown made with divs, I click it, wait and choose the option.

Select city = new Select(driver.findElement(By.id("city")));
city.selectByVisibleText("Hyderabad");

Selenium interview questions for 3 years experience

Q9. What is the difference between implicit, explicit and fluent waits?

30-second answer: Implicit wait applies to element searches. Explicit wait checks one condition for one step. Fluent wait also lets you set polling time and ignored exceptions.

WebDriverWait wait =
    new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(
    ExpectedConditions.elementToBeClickable(By.id("pay"))
).click();

Do not mix implicit and explicit waits. The total wait can become hard to predict. Avoid Thread.sleep because it always waits the full time.

Q10. What causes StaleElementReferenceException?

30-second answer: The page replaced an element after my code found it. The old reference no longer points to an element in the page.

I wait for the update and find the element again close to its use. Catching every stale error in a blind loop can hide a real bug.

Q11. How do you handle frames, windows and alerts?

30-second answer: I switch WebDriver to the right place before using it, then switch back.

driver.switchTo().frame("paymentFrame");
driver.findElement(By.id("card")).sendKeys("test-value");
driver.switchTo().defaultContent();

driver.switchTo().alert().accept();

For a new window, save the first handle, wait for a second one and switch to it. Never use real card data in tests.

Q12. What is the Page Object Model?

30-second answer: It is a design where a page class keeps locators and actions together. Tests read like user steps, and a screen change is fixed in one place.

class LoginPage {
    private final WebDriver driver;
    private final By email = By.id("email");
    private final By submit = By.id("submit");

    LoginPage(WebDriver driver) {
        this.driver = driver;
    }

    void login(String value) {
        driver.findElement(email).sendKeys(value);
        driver.findElement(submit).click();
    }
}

The private fields are an example of encapsulation. Prepare the related Java OOP questions too.

Q13. Which TestNG annotations do you use?

30-second answer: I use @Test for checks, before and after annotations for setup and cleanup, and @DataProvider to run a test with several inputs.

@BeforeMethod runs before each test method. @BeforeClass runs once before the first test method in that class.

Q14. What are hard and soft assertions?

30-second answer: A hard assertion stops the test method when it fails. A soft assertion collects failures until assertAll() is called.

Common mistake: Forgetting assertAll(). The test can then pass even though a soft assertion failed.

Q15. What if a click is intercepted?

30-second answer: Another element received the click. I check for a loader, banner or sticky header, wait for it to go and try the normal click.

A JavaScript click can skip the problem that a real user would face, so I do not use it as the first fix.

Selenium interview questions for 4 years experience

Q16. How do you run tests in parallel?

30-second answer: Each test thread needs its own driver and data. I can use a ThreadLocal driver, set parallel mode in TestNG and run sessions on Grid.

One static driver shared by all tests will let them control the same browser. Remove the ThreadLocal value after quit().

Q17. How do you run the same test with many inputs?

30-second answer: Use a TestNG DataProvider or read data from a file and pass it to the test. Keep expected results with the input.

@DataProvider(name = "badEmails")
public Object[][] badEmails() {
    return new Object[][] {{""}, {"asha"}, {"asha@"}};
}

@Test(dataProvider = "badEmails")
public void rejectsBadEmail(String email) {
    // enter email and check the message
}

Q18. How do you run Selenium in CI?

30-second answer: A pipeline starts a clean environment, sets browser options and test URLs, runs tests and saves reports, screenshots and logs.

Use secrets from the CI system, not the repository. Pipeline basics are covered in the DevOps interview questions.

Q19. What is Selenium Grid?

30-second answer: Grid sends browser sessions to other machines. It helps run tests in parallel and on different browser or operating system combinations.

Grid does not make unsafe tests ready for parallel use. Data and driver separation come first. If the app or test database is slow, adding more browsers can make the run less stable.

Selenium interview questions and answers for experienced engineers

Selenium interview questions and answers for experienced candidates often begin with, "Tell me about a failure." Use a real one.

Q20. How do you fix flaky tests?

30-second answer: A flaky test passes and fails without a related code change. I group failures by cause, reproduce the conditions and fix timing, shared data, locators or environment problems.

Retrying is only a short-term signal. Track a test that passes on retry. If you simply mark it green, the problem disappears from the report but still exists.

Q21. How would you handle CAPTCHA and OTP?

30-second answer: I do not automate around a live CAPTCHA. In a test environment, the team can disable it or provide an approved test key. For OTP, use a test service or a controlled test feature.

Those test features must not exist in production.

Selenium interview questions for 5 years experience

Q22. Design a Selenium framework.

30-second answer: I separate tests, page objects, driver setup, data, configuration and reports. I add clear waits, isolated data and CI support, while keeping the framework small.

Layer Job
Test User goal and checks
Page or component Locators and actions
API helper Fast data setup
Driver Start and end browser
Report Useful failure evidence

Explain what you would leave out too. A custom wrapper around every WebDriver method adds code and may hide useful errors.

Q23. Should test data be created through the browser?

30-second answer: Use the browser for the behaviour under test. Create other data through an API or database helper when that is safe and supported.

This makes tests faster and reduces unrelated failures. Keep at least one browser test for the real signup or order path.

Selenium interview questions for 7 years experience

Q24. How do you decide what not to automate in Selenium?

30-second answer: I keep logic in unit tests and service rules in API tests. Selenium covers a small set of important user paths and browser behaviour.

I also leave visual judgement and quick exploration to people. See manual vs automation testing.

Q25. Would you replace Selenium with another tool?

30-second answer: I compare browser support, team skills, current tests, speed, debugging and maintenance cost. I run a small trial before moving a working suite.

A new tool will not fix bad data or poor tests. Move only when the expected gain is worth the rewrite. Explain how both suites would run during the change and when the old one would be removed.

Interview note: At 7 years, "it depends" is fine only if you name what it depends on and then choose.

Failure practice: symptom to first check

Interviewers may show an error and ask for your first step. Learn the likely reason, but keep checking before you change code.

Symptom First check
NoSuchElementException Wrong locator, frame, page or timing
TimeoutException The last condition and a screenshot
Test passes alone but fails in the suite Shared data, order or driver
Passes locally but fails in CI Window size, test URL, speed and browser
Works in Chrome only Browser support and unsafe assumptions
Report shows no useful detail Screenshot, URL, logs and test data

For example, a save button works on your laptop but is hidden in CI. The CI window may be smaller, so a cookie banner covers it. Set a known window size and close the banner as a user would. A longer sleep would not fix that.

When you explain such a problem, name the evidence. "The screenshot showed the banner over the button" is stronger than "I guessed it was a wait issue."

How to prepare for a Selenium round

  1. Automate login, search and checkout on a site made for practice.
  2. Add page objects, a data provider and screenshots on failure.
  3. Run two tests in parallel and fix shared data.
  4. Put the project in Git and revise Git interview questions.
  5. Explain one failure from first symptom to final check.

Also write a locator by hand on a plain HTML page. Many candidates copy one from the browser and cannot explain it. Practise using text, attributes and a parent row without long page paths.

If test design still feels weak, first revise manual testing interview questions. Good automation begins with a good check.

Frequently Asked Questions

Which language should I use in a Selenium interview?
Use the language named in the job post. Java is used in the examples here, and Selenium also supports Python, C#, JavaScript and Ruby. The WebDriver ideas stay the same, but your language basics will also be tested.
Is Selenium enough to get an automation testing job?
Selenium alone is rarely enough. You also need test design, one programming language, a test runner, Git, API testing basics and some CI knowledge.
Do I need to know Selenium 3 for interviews?
Know the main change: Selenium 4 uses the W3C WebDriver standard and no longer needs the old JSON Wire Protocol. Write new answers with Selenium 4 syntax, such as Duration objects for waits.
Can Selenium test mobile apps or APIs?
Selenium automates web browsers. Appium is commonly used for mobile apps, and API tools or HTTP libraries are better for APIs. A test project can use these together.
How do I prepare for a 7-year Selenium interview?
Prepare to design a framework, choose test levels, run tests in parallel, control flaky tests and guide a team. You should be able to explain when a browser test is the wrong choice.
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 3 December 2026 LinkedIn
Chat with us