These Selenium interview questions for freshers cover what interviewers ask candidates with 0–3 months of automation experience: what Selenium is, project setup, WebDriver and WebElement methods, and locators. The answers are detailed enough to explain out loud, with code where it helps. For the shorter list everyone revises, see the top 50 Selenium interview questions.

Selenium interview questions by experience: Freshers · 1 year · 3 years · 5 years
Planning your learning? Follow the Selenium automation testing roadmap.

Introduction to Selenium

1. What is Selenium? Give a brief history of its versions.

Selenium is a free, open-source suite of tools for automating web browsers. It was originally developed by Jason Huggins in 2004 at ThoughtWorks.

  • Selenium 1 (RC - Remote Control): Used JavaScript injection to control browsers. Required a running Selenium RC server. Now deprecated.
  • Selenium 2 (WebDriver): Merged Selenium RC with WebDriver (created by Simon Stewart). Introduced direct browser communication — much faster and stable.
  • Selenium 3: Used JSON Wire Protocol (now W3C standard). Added GeckoDriver for Firefox, improved Grid support.
  • Selenium 4 (Current): Full W3C WebDriver compliance, Chrome DevTools Protocol (CDP) integration, new Grid 4 architecture, Relative Locators, BiDi API.
  • Selenium is NOT a testing framework — it is a browser automation tool. TestNG/JUnit serve as the testing framework on top.

2. What are the components of the Selenium Suite?

Selenium is not just one tool — it is a suite of 4 components:

  • Selenium IDE: Browser extension (Chrome/Firefox) for record-and-playback. Exports tests in Java, Python, etc. Best for beginners and quick prototyping.
  • Selenium WebDriver: Core API that directly communicates with browsers. The heart of any Selenium automation project.
  • Selenium Grid: Allows running tests on multiple machines and browsers in parallel. Reduces total execution time significantly.
  • Selenium RC (deprecated): The old server-based approach. Replaced completely by WebDriver. No longer maintained.

3. What are the advantages and limitations of Selenium?

4. How does Selenium compare to Cypress and Playwright?

Advertisement

Environment Setup

5. How do you set up a Selenium WebDriver project from scratch with Maven?

Step-by-step setup for a Selenium + Java + Maven project:

  • 1. Install Java JDK 11+ and set JAVA_HOME environment variable
  • 2. Install Eclipse IDE or IntelliJ IDEA
  • 3. Create Maven project: File > New > Maven Project in Eclipse
  • 4. Add dependencies to pom.xml: selenium-java, testng, webdrivermanager
  • 5. WebDriverManager auto-downloads correct ChromeDriver: WebDriverManager.chromedriver().setup();

6. Create test class: WebDriver driver = new ChromeDriver(); driver.get("https://google.com");

  • 7. Run as TestNG test or via mvn test command
  • Key dependency versions: selenium-java 4.x, testng 7.x, webdrivermanager 5.x

6. What is WebDriverManager and why is it used instead of manual ChromeDriver setup?

WebDriverManager (by Boni Garcia) automatically downloads and configures the correct browser driver binary.

  • Problem with manual setup: ChromeDriver version must match Chrome browser version exactly — mismatch causes errors
  • WebDriverManager solution: Detects installed browser version and downloads matching driver automatically
  • Usage: WebDriverManager.chromedriver().setup(); // Call before new ChromeDriver()
  • Also supports: WebDriverManager.firefoxdriver().setup(); WebDriverManager.edgedriver().setup();
  • Selenium 4.6+ includes Selenium Manager which does this automatically — WebDriverManager may not be needed
  • Benefit: No more manual driver downloads, no path configuration, works in CI/CD without setup

7. What is the difference between driver.get() and driver.navigate().to()?

Both navigate to a URL, but there are subtle differences:

driver.get(url): Waits for page to load completely before returning. Simple, direct navigation.

driver.navigate().to(url): Also navigates but is part of the Navigation interface which has more methods.

driver.navigate().back(): Goes back in browser history

driver.navigate().forward(): Goes forward in browser history

driver.navigate().refresh(): Refreshes current page

In practice: driver.get() is most commonly used for navigation in tests.

Key difference: there is no behavioural difference: navigate().to() runs the same command as get(), and the Navigation interface adds back(), forward() and refresh()

8. What is the difference between driver.close() and driver.quit()?

This is a very commonly asked interview question.

driver.close(): Closes only the currently focused browser window/tab. If multiple windows are open, others remain open.

driver.quit(): Closes ALL browser windows AND kills the WebDriver session completely. Also removes temp files.

Best Practice: Always call driver.quit() in @AfterMethod or finally block to prevent browser processes from hanging.

Memory leaks: Calling driver.close() and not driver.quit() leaves the chromedriver.exe process running in background.

Example: If 3 tabs are open — driver.close() closes 1, driver.quit() closes all 3 and ends session.

WebDriver Core Methods

9. List and explain the most important WebDriver interface methods.

The WebDriver interface provides these core methods:

  • get(String url): Navigate to URL and wait for page load
  • getTitle(): Returns current page title as String
  • getCurrentUrl(): Returns current URL as String
  • getPageSource(): Returns full HTML source of current page
  • findElement(By by): Returns first matching WebElement; throws NoSuchElementException if not found
  • findElements(By by): Returns List<WebElement>; returns empty list if none found
  • close(): Close current window
  • quit(): Close all windows and end session
  • getWindowHandle(): Returns unique identifier (String) of current window
  • getWindowHandles(): Returns Set<String> of all open window handles
  • switchTo(): Returns TargetLocator for switching to frames, windows, alerts
  • manage(): Returns Options for cookies, timeouts, window management
  • navigate(): Returns Navigation for back/forward/refresh/to

10. How do you manage browser windows (maximize, resize, get dimensions)?

Window management is done via driver.manage().window():

driver.manage().window().maximize(): Maximize browser window

driver.manage().window().fullscreen(): Full screen mode (F11 equivalent)

driver.manage().window().minimize(): Minimize browser window (Selenium 4)

driver.manage().window().setSize(new Dimension(1366, 768)): Set specific size

driver.manage().window().setPosition(new Point(0, 0)): Set window position

Dimension size = driver.manage().window().getSize(): Get current size
Point pos = driver.manage().window().getPosition(): Get window position
  • Headless Chrome: Options automatically sets window size via --window-size=1920,1080 argument

Locators — Finding Web Elements

11. What are all the locator strategies in Selenium? Which is the best and why?

Selenium provides 8 locator strategies. Priority order for reliability: ID > CSS > XPath > others.

  • By.id("username"): Fastest, most unique — ALWAYS prefer when available. IDs must be unique per HTML spec.
  • By.name("email"): Good for form elements; less unique than ID
  • By.className("btn-primary"): Risky — multiple elements often share a class
  • By.tagName("input"): Too broad; returns many elements. Use with findElements()
  • By.linkText("Click Here"): Exact text match for <a> tags — fragile if text changes
  • By.partialLinkText("Click"): Partial text match for <a> tags
  • By.cssSelector("#form > input.username"): Fast, powerful, second best choice. CSS is browser-native.
  • By.xpath("//input[@id=\"user\"]"): Most flexible — can traverse any direction in DOM. Slower than CSS.
  • Best Practice: ID > CSS Selector > XPath. Avoid className and tagName for unique identification.

12. Write CSS selectors for various scenarios.

CSS Selector syntax for common scenarios:

  • By ID: #username or input#username
  • By Class: .btn-primary or button.btn-primary
  • By Attribute: input[type='submit'] or a[href='/login']
  • Child element: form > input (direct child only)
  • Descendant: div input (any level below div)
  • Multiple classes: button.btn.btn-primary
  • Starts with: input[id^="user'] — ID starts with 'user"
  • Ends with: input[id$="name'] — ID ends with 'name"
  • Contains: input[id*="ser'] — ID contains 'ser"
  • nth-child: ul li:nth-child(3) — 3rd list item
  • First child: ul li:first-child
  • Adjacent sibling: label + input — input immediately after label

13. Explain XPath in detail. What are axes and how are they used?

XPath (XML Path Language) is a query language for navigating DOM elements.

  • Basic XPath: //tagName[@attribute='value']
  • contains(): //input[contains(@class,"btn")] — partial attribute match
  • starts-with(): //input[starts-with(@id,"user")] — attribute starts with
  • text(): //button[text()='Login'] — match by exact visible text
  • normalize-space(): //button[normalize-space()='Login'] — handles extra spaces
  • AND condition: //input[@type='text' and @name='email']
  • OR condition: //input[@type='text' or @type='email']

XPath Axes

parent:: — //input[@id='pass']/parent::div — parent element
ancestor:: — //span/ancestor::form — first form ancestor
following-sibling:: — //label/following-sibling::input — input after label
preceding-sibling:: — //td[3]/preceding-sibling::td[1]
child:: — //div/child::input — direct children
descendant:: — //form/descendant::input — all inputs inside form
  • Index: (//input[@type='text'])[2] — second text input on page

14. What is the difference between CSS Selector and XPath? When to use each?

WebElement Methods

15. What are all the WebElement methods and what do they do?

WebElement represents a DOM element. Key methods:
  • click(): Clicks the element. Scrolls into view if needed in Selenium 4.
  • sendKeys(CharSequence... keys): Types text. Also used for file upload with file path.
  • clear(): Clears text from input field. Does NOT work on read-only fields.
  • getText(): Returns visible text of the element (innerText). Returns empty string if not visible.
  • getAttribute(String name): Returns value of HTML attribute. e.g., getAttribute("href"), getAttribute("value")
  • getCssValue(String property): Returns computed CSS property. e.g., getCssValue("color"), getCssValue("font-size")
  • getTagName(): Returns HTML tag name (e.g., "input", "div", "button")
  • isDisplayed(): Returns true if element is visible on page. Throws if element doesn't exist.
  • isEnabled(): Returns true if element is not disabled. Useful before clicking submit buttons.
  • isSelected(): Returns true for checkboxes/radio buttons that are checked.
  • getSize(): Returns Dimension object with width and height of element
  • getLocation(): Returns Point object with x, y coordinates of element on page
  • getRect(): Returns Rectangle — combines location + size (Selenium 4)
  • getDomProperty(String name): Gets DOM property (Selenium 4) — like getAttribute but for DOM properties
  • submit(): Submits a form. Equivalent to pressing Enter in a form field.

16. What is the difference between getAttribute() and getText()?

A common but important distinction in Selenium:

  • getText(): Returns the visible text content rendered between tags. e.g., <button>Login</button> → getText() returns 'Login'
  • getAttribute("value"): Returns the value attribute of input fields. e.g., <input value="admin'> → 'admin"
  • getText() on input fields returns empty string — use getAttribute("value") instead
  • getAttribute("innerHTML"): Returns inner HTML including tags
  • getAttribute("textContent"): Returns all text including hidden text (unlike getText())
  • getAttribute("class"): Returns full class attribute string
  • getDomProperty("value"): Gets current value of input (Selenium 4) — reflects user-typed text even if attribute hasn't changed

17. How do you verify if an element is present, visible, enabled, or selected?

Different checks for element state:

  • Element Exists (in DOM): Use findElements() — if list.size() > 0, element exists
  • Element Visible: element.isDisplayed() — true if element has dimensions and is not hidden via CSS
  • Element Enabled: element.isEnabled() — false for disabled form fields, grayed out buttons
  • Element Selected: element.isSelected() — true for checked checkboxes, selected radio buttons, selected options
  • Element in Viewport: Use JavaScript: js.executeScript("return arguments[0].getBoundingClientRect().top >= 0", el)
  • Difference: isDisplayed() can be true even if element is off-screen. An element can exist in DOM but not be displayed.
  • Safe check pattern: Use WebDriverWait + ExpectedConditions.visibilityOf(element) instead of direct isDisplayed()

Quick-Fire Questions

Short answers to revise the night before.

18. What is Selenium?

Open-source framework to automate web browser actions like clicking, typing, and navigation.

19. What languages does Selenium support?

Java, Python, C#, JavaScript, Ruby, Kotlin.

20. What is the latest version of Selenium?

Selenium 4.x (most recent stable). Introduced W3C WebDriver standard.

21. What is WebDriver?

WebDriver is the main interface in Selenium that controls the browser. ChromeDriver, FirefoxDriver implement it.

22. What is Maven?

Build and dependency management tool. We use it to automatically download Selenium JAR files via pom.xml.

23. What is pom.xml?

Project Object Model file in Maven. Contains project dependencies, plugins, and build configuration.

24. What is JDK vs JRE?

JDK (Java Development Kit) is for writing and compiling code. JRE (Java Runtime Environment) is just for running Java programs.

25. What is an interface in Java?

An interface defines a contract (methods without implementation). WebDriver is an interface implemented by ChromeDriver, FirefoxDriver, etc.

26. What is the difference between == and .equals() in Java?

== checks object reference (memory address). .equals() checks the actual content/value. Always use .equals() to compare Strings.

27. What is driver.getTitle()?

Returns the title of the current web page as a String.

28. What is driver.getCurrentUrl()?

Returns the URL of the currently loaded web page.

29. What does driver.manage().window().maximize() do?

Maximizes the browser window to fill the entire screen.

30. Why do we use Selenium over manual testing?

Selenium is faster, reusable, runs 24/7, handles regression testing automatically, and is more accurate for repetitive tasks.

How to Prepare as a Fresher

  • Write and run a small test yourself: open a site, log in, assert a message. Interviewers can tell who has actually run code.
  • Practise locators on the roadmap practice sites until you can write a CSS selector and an XPath for any element.
  • Know close() vs quit(), get() vs navigate(), findElement vs findElements and getText vs getAttribute without hesitation.
  • Next, read the questions for 1 year of experience: waits are always the next topic.