Selenium with Java - Interview Questions &
Answers
Part 1: Core Java
Q: What are OOPs concepts in Java?
A: Encapsulation, Inheritance, Polymorphism, Abstraction.
Q: Difference between Interface and Abstract Class?
A: Interface supports multiple inheritance and only abstract methods (Java 8+ allows default
methods). Abstract class allows concrete + abstract methods, but supports single inheritance.
Q: What is Exception Handling?
A: Mechanism to handle runtime errors using try-catch-finally. 'throw' is used to explicitly throw an
exception, 'throws' declares exceptions.
Q: String vs StringBuilder vs StringBuffer?
A: String is immutable. StringBuilder is mutable and not thread-safe. StringBuffer is mutable and
thread-safe.
Q: Difference between HashMap and Hashtable?
A: HashMap is non-synchronized, allows one null key and many null values. Hashtable is
synchronized and does not allow null keys/values.
Part 2: Selenium Basics
Q: What is Selenium?
A: An open-source automation testing tool for web applications across multiple browsers/platforms.
Q: Difference between findElement and findElements?
A: findElement returns first matching element and throws NoSuchElementException if not found.
findElements returns a list (empty if not found).
Q: What are locators in Selenium?
A: Strategies to find elements on a page: id, name, className, tagName, linkText, partialLinkText,
cssSelector, xpath.
Q: What is XPath?
A: A query language to locate elements. Absolute XPath starts from root (/html/body/..). Relative
XPath starts from anywhere (//input[@id='username']).
Q: What are waits in Selenium?
A: Implicit wait is global and applies for all elements. Explicit wait is conditional for specific element.
Fluent wait allows polling frequency.
Part 3: Framework & Industry
Q: What is TestNG?
A: A testing framework for Java. Provides annotations (@Test, @BeforeTest), parallel execution,
data-driven testing, and reports.
Q: What is Page Object Model (POM)?
A: Design pattern that creates an object repository for web pages, improving maintainability and
readability.
Q: How do you handle dropdowns?
A: Using Select class: Select s = new Select([Link]([Link]('id')));
[Link]('Option');
Q: How do you handle alerts?
A: Switch to alert using [Link]().alert(). Methods: accept(), dismiss(), getText().
Q: How do you take screenshots?
A: File src = ((TakesScreenshot)driver).getScreenshotAs([Link]); [Link](src,
new File('[Link]'));