Selenium Automation 400 Interview Questions
Selenium Automation 400 Interview Questions
1
CoderBaba Selenium Testing
2. Abstraction vs Encapsulation
Explain the difference between Abstraction (hiding complex details and showing only the
essential features) and Encapsulation (bundling data and methods into a single unit or class).
What are the different types of asserts in Selenium, such as assertEquals, assertTrue,
assertFalse, assertNotNull, and their use cases in automation testing?
Explain the different types of waits in Selenium, such as Implicit Wait, Explicit Wait, and Fluent
Wait, and how each one is used to handle dynamic web elements in automation.
5. Different Exceptions
What are some common exceptions you might encounter in Selenium, such as
NoSuchElementException, TimeoutException, StaleElementReferenceException, and how do
you handle them?
Explain or write a code to switch between multiple browser windows using Selenium
WebDriver.
Example Code:
2
CoderBaba Selenium Testing
Write a piece of code to check if a number is a palindrome (reads the same forward and
backward).
Example Code:
8. findElement vs findElements
Explain the difference between findElement (returns a single element) and findElements
(returns a list of elements) methods in Selenium, and when to use each one.
3
CoderBaba Selenium Testing
1. What are the different types of waits in Selenium, and when would you use each one?
This question tests your understanding of Implicit Wait, Explicit Wait, and Fluent Wait in
handling dynamic web elements during automation.
Explain the process of handling Alerts, Confirmations, and Prompts in Selenium, and the
methods like alert.accept(), alert.dismiss(), etc.
3. How do you identify and handle broken links in a website using Selenium?
This question tests your knowledge of detecting and handling broken links in an automated
test. Describe the approach for checking the HTTP status of links.
4. What’s the difference between findElement and findElements in Selenium, and when
would you use each?
Explain the distinction between these two methods in Selenium, focusing on how findElement
returns a single element and findElements returns a list of elements.
5. Can you explain the Object-Oriented Programming (OOP) concepts you've applied in your
Selenium automation projects?
6. How do you handle pagination in Selenium when testing a web application with multiple
pages of data?
Describe how to navigate through pagination in a web application, handling dynamic page
numbers and ensuring that you can test across multiple pages.
7. How do you implement parallel test execution in Selenium, and what are the benefits?
Explain how to run tests in parallel using TestNG or JUnit, and discuss the advantages of parallel
execution in speeding up the testing process.
4
CoderBaba Selenium Testing
8. Can you provide a code example for detecting and handling broken links in a web page
using Selenium?
Provide a code snippet to detect and report broken links by checking their HTTP response status
during automation.
9. How do you handle multiple windows or tabs in Selenium, and can you provide an example
of switching between them?
Describe how to manage and switch between multiple windows or tabs using window handles
in Selenium WebDriver.
10. Can you explain the role of annotations in Selenium test frameworks, such as TestNG or
JUnit?
4. Write a Java program to reverse a string and calculate its length without using reverse
7. Could you describe your experience with mobile testing and provide examples?
8. Write Selenium code to extract table and row values from a website.
10. What issues have you faced while running Selenium scripts in Java?
13. Explain the concept of XPaths and their importance in automation testing.
14. Which framework(s) are you currently using for test automation?
5
CoderBaba Selenium Testing
18. What is POM (Page Object Model), and how does it help in test automation?
2.what is your approach if developer says the issue which was raised is not a bug
3.What are the step you will consider for building automation framework from scratch,
6.What is your approach to start the project if you don't have any single requirement docs or
data?
13.In Sign page even after providing correct credentials it shows popup with some error msg
what might be the reason but working fine in manual
14.When some persons are not available and we need to finish that task immediately, how
did you handled
15.In cucumber I never want use login details again an again then what would be my
approach
6
CoderBaba Selenium Testing
1. What is Selenium?
2. What are the different types of Selenium tools?
3. What is Selenium WebDriver?
4. What is the difference between Selenium IDE and Selenium WebDriver?
5. How do you launch a browser using Selenium WebDriver?
6. What are the different types of browsers supported by Selenium?
7. How do you handle alerts and pop-ups in Selenium?
8. What is the use of Selenium Grid?
9. How do you run Selenium tests in parallel?
10. What are the advantages of using Selenium?
These questions cover the basics of Selenium, WebDriver, locators, TestNG, and advanced
Selenium concepts.
8
CoderBaba Selenium Testing
2. Find the Largest Element in an Array: Find and print the largest element in an array.
5. Fibonacci Series: Generate the first *n* numbers in the Fibonacci sequence.
6. Check for Prime Number: Write a program to check if a given number is prime.
8. Array Sorting: Implement sorting algorithms like bubble sort, merge sort, or quicksort.
10. Duplicate Elements in an Array: Find and print duplicate elements in an array.
13. Implement a Stack: Create a stack data structure with basic operations (push, pop).
14. Implement a Queue: Create a queue data structure with basic operations (enqueue,
dequeue).
15. Inheritance and Polymorphism: Implement class hierarchy and demonstrate polymorphism.
16. Exception Handling: Demonstrate the use of try-catch blocks to handle exceptions.
17. File I/O: Read from and write to a file using Java’s file I/O capabilities.
20. Recursive Algorithms: Solve problems using recursion, like computing factorial or Fibonacci
sequence.
9
CoderBaba Selenium Testing
21. Swap two Numbers: Swap two numbers without using a third variable.
3. I see you have used the TestNG framework. Can you explain how you configured TestNG in
your project?
4. How do you write test scenarios for searching in a search box? Can you give an example?
Describe the process of creating test scenarios for verifying search functionality, including input
validation, result verification, and edge case handling.
Explain the structure of your automation framework and where you place reusable
components (e.g., utility classes, functions, or Page Objects) for easier maintenance and better
test scalability.
10
CoderBaba Selenium Testing
7. What are the different Selenium locators, and which one do you prefer in your projects?
Discuss the different types of Selenium locators such as ID, Name, Class Name, Tag Name, Link
Text, Partial Link Text, CSS Selector, and XPath, and explain when and why you would use each.
8. Write a Selenium test script to search for the "Java" keyword in Google search bar, count
the number of links on the page, open each link in a new window, get the title of the opened
webpage, and close the browser.
1st Round:
1. Tell me about yourself.
2. What are the various selenium components, and which components are you using?
4. What are the various locators you are using in your day-to-day life?
11
CoderBaba Selenium Testing
25. The difference between implicitly, explicitly, webdriver wait and thread.sleep.
32. How do you get to know if the developer has fixed the issues or not?
12
CoderBaba Selenium Testing
2nd round:
1. Tell me about yourself.
3. For which functionality module have you performed performance testing in your project?
5. Which language do you use for Appium testing? ( I have mentioned this in my resume)
7. Can we use the same code in the Appium, the test script developed for a web app?
8. What is Jenkins?
Abstract Class:
• An abstract class is used when you want to provide common functionality to subclasses
while leaving some methods to be implemented by the subclasses. It can have both
abstract methods (methods without a body) and concrete methods (methods with a
body).
13
CoderBaba Selenium Testing
Interface:
• An interface is used when you want to define a contract for classes to implement. It only
contains method signatures (no implementation), and classes that implement the
interface are required to provide the implementation.
o You need to ensure that certain methods are implemented by classes, but the
classes don't need to inherit any common behavior.
o You need to define multiple behaviors that can be applied to different classes.
o You want to achieve multiple inheritance in Java, which is not possible with
abstract classes.
Key Differences:
• Interface cannot have method implementations (prior to Java 8), and all methods are
abstract by default (except default methods and static methods in Java 8 and above).
While it’s technically possible to create a framework with all static methods, it’s not advisable
for several reasons:
1. Limited Extensibility: Static methods are tied to a particular class and cannot be
overridden. This makes the framework hard to extend or customize, as you cannot
replace or change the behavior dynamically.
14
CoderBaba Selenium Testing
2. Testability Issues: Static methods make it difficult to mock or test components, as they
don't rely on instance-based behaviors. It’s hard to isolate dependencies when
everything is static.
3. Code Reusability: Static methods cannot benefit from polymorphism, which is key for
achieving reusability. You won’t be able to easily change implementations of certain
functions based on the context.
4. Global State: Static methods hold state globally, which may lead to unexpected results,
especially in multi-threaded applications or when state changes are not controlled
properly.
Best Practice: It’s better to design your framework in an object-oriented manner, using
instance methods where required, to allow for flexibility, inheritance, and better unit testing.
3. Int arr = {1, 2, 3, 4, 5, 7, 8, 9}; Skip 3 and all elements after 3, then skip 7 and then give
some output.
Solution:
if (arr[i] == 3) {
// Skipping 7
if (arr[i] == 7) {
15
CoderBaba Selenium Testing
continue; // Skip 7
}}
Output:
12
124589
Solution:
import java.util.HashMap;
interface DataStore {
@Override
map.put(key, value);
@Override
16
CoderBaba Selenium Testing
return map.get(key);
// Adding data
dataStore.addData(1, "Apple");
dataStore.addData(2, "Banana");
// Retrieving data
Explanation:
• The interface DataStore defines methods for adding and retrieving data from a
HashMap.
• The DataStoreImpl class implements the interface and provides the actual
implementation for adding and getting values from the map.
• The main method demonstrates adding data and retrieving it using the implemented
methods.
Solution:
17
CoderBaba Selenium Testing
import java.util.LinkedHashSet;
set.add(c);
result.append(c);
}
}
JAVA
18
CoderBaba Selenium Testing
7) Reverse Number - first explain with methods then move with loop and if conditions.
3) Static variables-methods-classes
6) Constructors cannot be overridden because it's should name the same class name.
interface cannot have constructor in java, because interface not have any instance member so
nothing to construct.
Methods present in the interface are only declared not defined, As there is no implementation
of methods,
there is no need of making objects for calling methods in the interface and thus no point of
having constructor in it
Lists >
ArrayList = it is not fixed value, it is an ordered collection, it accepts duplicate values. No
Thread Safe
=================
> Linked List = it is not fixed value, changes can be done with this linked list. No Thread Safe
===================
20
CoderBaba Selenium Testing
The HashSet class has many useful methods. For example, to add items to it, use the add()
method:
when you using collections that time you must be using Wrapper classes
Another useful method is the toString() method, which is used to convert wrapper objects to
strings.
In the following example, we convert an Integer to a String, and use the length() method of the
String class to output the length of the "string":
12) Why Java not complete OOPS. - because it support Primitives types.
The this keyword is used to refer to the current object, while the super keyword is used to refer
to the parent object.
The this keyword can be used to access the current object's instance variables and methods,
while the super keyword can be used to access the parent object's instance variables and
methods.
21
CoderBaba Selenium Testing
• How do you use get() and navigate() methods in Selenium? What is the difference
between them?
• What is the difference between driver.close() and driver.quit() in Selenium? When would
you use each?
• What are assertions in Selenium? Can you explain the different types of assertions
available in TestNG?
• What is POM (Page Object Model) and how does it work in Selenium?
• Can you explain BDD (Behavior-Driven Development) and its integration with Selenium
for test automation?
• How would you perform localization and globalization testing using Selenium?
• Can you explain the difference between a Scenario and a Scenario Outline in
Cucumber? When would you use each?
22
CoderBaba Selenium Testing
7) Hooks
• What are hooks in Cucumber? Can you explain the different types of hooks and when
they are executed?
• Can you break down the statement WebDriver driver = new ChromeDriver() and explain
the role of each keyword?
• Why do we use WebDriver for automation? Why not other browsers like Firefox or
Safari? What are the advantages of WebDriver over other tools?
10) Script Working in Night But Not the Next Day - Reasons
• Your Selenium script runs fine at night but fails the next day. What could be the reasons
for this?
• What are the differences when performing cross-browser testing in Selenium? How
would you approach running tests on different browsers?
12) Thread.sleep, Fluent Wait, Implicit Wait, and WebDriver Wait (Explicit Wait)
• Can you explain the difference between Thread.sleep(), FluentWait, ImplicitWait, and
ExplicitWait in Selenium?
• Why and when should you use each of these waits in Selenium?
Example:
o After: driver.manage().timeouts().scriptTimeout(Duration.ofMinutes(2));
o driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".classlocator")));
23
CoderBaba Selenium Testing
• Can you explain the usage of Actions, Select, and Alert classes in Selenium?
o How do you handle mouse actions, keyboard actions, and drag-and-drop actions
using the Actions class?
• Can you explain XPath axes such as preceding, following, sibling, and parent? How would
you use them in Selenium for locating elements?
1) Descendant in XPath
• Can you explain what a descendant is in XPath? How is it used to locate elements in a
web page?
• Why can't Captchas and OTPs be automated using Selenium? What are the challenges
involved?
• What are Desired Capabilities in Selenium? How are they used in a test automation
framework?
• How can you switch to the 3rd child window in Selenium WebDriver? Can you explain
the code snippet for this?
24
CoderBaba Selenium Testing
driver.switchTo().window(thirdWindow);
5) Switch to Frames
• How do you switch between frames in Selenium WebDriver? Can you provide an
example?
• What are the different ways to refresh a page in Selenium? Explain with examples.
o driver.navigate().refresh();
o driver.navigate().to(driver.getCurrentUrl());
o driver.findElement(By.id("username")).sendKeys(Keys.F5);
• What are the different types of exceptions in Selenium? Can you provide examples of
how they occur and how to handle them?
• What is the difference between checked and unchecked exceptions in Java? Provide
examples of both.
9) JavaScript Executor
• What is the JavascriptExecutor interface in Selenium? How would you use it for:
o Getting an element
o Clicking an element
o Highlighting an element
Example:
js.executeScript("window.scrollBy(0,500)"); // To scroll
25
CoderBaba Selenium Testing
Thread.sleep(2000);
js.executeScript("document.querySelector('.tableFixHead').scrollTop=500");
• How can you take a screenshot of a failed test case using Selenium? Can you explain the
implementation and the role of TakesScreenshot interface? Example code:
FileUtils.copyFile(source, file);
• What is the DOM (Document Object Model)? What is a Stale Element Reference
Exception in Selenium, and how can you avoid it?
• Can you explain the difference between the old WebDriver architecture and the latest
WebDriver architecture?
• How do you handle SSL security certificate pop-ups and authentication pop-ups in
Selenium? Can you provide an example of handling authentication via
http://username:password@url?
• What are TestNG priorities, and how can you assign priorities to test methods? Can a
priority be negative? If yes, how does it affect test execution order?
26
CoderBaba Selenium Testing
• How do you integrate TestNG XML with a Page Object Model (POM) framework? Can
you provide an example?
• What is Maven, and how is it used in a Selenium framework? Can you explain the
pom.xml file in detail?
o Can you explain the project creation process in Jenkins and integration with Git?
• What are MetaGroups in TestNG? How do they help in test execution and reporting?
driver.navigate.refresh();
driver.navigate.to(driver.getCurrentURL());
driver. findElement(By.id("username")).sendKeys(Keys.F5);
click element
highlight element
JavascriptExecutor js=(JavascriptExecutor)driver;
27
CoderBaba Selenium Testing
Thread.sleep(2000);
js.executeScript("document.querySelector('.tableFixHead').scrollTop=500");
FileUtils.copyFile(source, file);
using http://username:password@url_without_https in
driver.get()
) Maven understanding
28
CoderBaba Selenium Testing
creationa nd GIT.
) MetaGroups - TestNG
) Context Node
#Strings
1. Reverse a String
#Arrays
29
CoderBaba Selenium Testing
2)What are the different ways to input text other than sendkeys()?
4)Is it possible to read PDF files using Selenium WebDriver? If yes, then how?
12) How can you disable images on a Web Page as it takes more to load a page?
13) How would you handle the alert popups in Selenium WebDriver?
16) Suppose a file is 100mb, how can I wait for the file to be downloaded completely?
17) Explain Soft Assertions & Hard Assertions in the Automation Framework.
18) Can you access the OTP code from your email through Selenium Automation? If yes then
how?
30
CoderBaba Selenium Testing
21) How can you handle cookies in a Selenium WebDriver? Will you be able to use the same
cookies to restore the session of Web application?
22)How would you automate a scenario where you need to verify specific colors -Theme
testing?
23) What are the different Chrome Options you have used so far in your automation
framework?
24) The Automation script needs to run on multiple browsers and platforms. How do you
handle this?
25)How will you give the total time required for the test case to automate?
29)What are the common Selenium Exceptions you faced so far and how have you handled
them?
30)What is the CI/CD pipeline & how will you implement it in your automation framework?
INTERVIEW QUESTIONS
31
CoderBaba Selenium Testing
4. According to you which was the complex part of the project from testing point of view.
6. How many test cases have you designed? How many you wrote in a day?
2. How that Seed has sent you here for an interview when you are working in the same
company.
3. Where it is located?
HR Questions
1. Introduce yourself.
9. Where would you like to see yourself 5 years down the line.
5. How will you convince a developer who is not ready to resolve the bug you have raised?
33
CoderBaba Selenium Testing
7. Have you done White Box Testing? Do you know what type of bugs you can trace through this
type of testing?
12. How do you decide which test cases to consider for Regression Testing?
37. What is the difference between Web application and Client Server Application?
39. What is difference between Black box testing and White box testing?
40. What is the difference between Authentication and Authorization give an example.
41. Other than functionality what else you should test in Web Application?
-------------------
java :
1) what is polymorphism?
2) Exception handling ?
35
CoderBaba Selenium Testing
Selenium :
2) write a xpath or make my trip application? write the xpath for Holiday and no need to change
the existing xpath .By using the same xpath you need to identify the hotels as well.
TestNG
4) what is the difference b/w Before Test and Before method ? How will it work? Give me an
example ?
BBD:
36
CoderBaba Selenium Testing
Manual Testing :
What is estimation?
Jenkins :
how you will create the job and how it will execute ?
37
CoderBaba Selenium Testing
38