Rahul Shetty

Selenium is a tool widely used for the automated testing of web applications. 90% of companies use Selenium for UI automation. It’s a popular option because Selenium can be written in many programming languages including Java, JavaScript, C#, and Python. 

In this article, we’ll look at important Selenium questions to help you ace your next job interview. 

1. What is Selenium?

Selenium is a tool for automating everything you can do inside a web browser. It automates functional aspects of web-based applications and can run across all browsers and platforms.

Person with headphones in front of laptop

2. Which are the components of the Selenium suite

Selenium is not just a single tool or a utility. Rather, it’s a bundle of multiple test tools, referred to as a suite. Each of the tools is designed to meet specific criteria for testing and testing environments.

The suite package contains the following set of tools:

Selenium WebDriver with Java -Basics to Advanced+Frameworks

Last Updated November 2022

  • 329 lectures
  • All Levels
4.6 (91,400)

“TOP RATED #1 Master SELENIUM java 4 (Latest) course” -5 Million students learning worldWide with great collaboration | By Rahul Shetty

Explore Course

3. What are the advantages of Selenium in the automation testing world?

Selenium is a free open-source platform and supports a wide array of users and support communities. It’s compatible across systems, making it friendly for Windows, Linux, and Mac users. It supports Java, Python, Perl, PHP, C#, and Ruby programming languages.

Since Selenium is compatible with cross-browser testing, it works on almost all common browsers including Chrome, Firefox, Edge, Internet Explorer and Safari. Another benefit is that Selenium Grid allows for parallel execution. 

4. What is WebDriver?

WebDriver is a simple and concise programming interface. As an object-oriented and lightweight API, it drives the browser through interface-type reference variables.

5. What is Selenium 4?

Selenium 4 is the latest version of Selenium WebDriver, which will be fully standardized with W3C. Since most browsers such as Chrome, Safari, Firefox, Internet Explorer, and Edge follow W3C standardization, browser drivers will interact with Selenium WebDriver in W3C standard protocol.

6. What are some noteworthy Selenium 4 features?

7. What are all the relative locators in Selenium 4?

We have several methods of finding a (relative) element close by. These are:

8. What are the different waits in Selenium WebDriver?

There are three types of waits in WebDriver:

  1. Implicit Waits: This is a wait timeout that applies to an instance on a WebDriver. It implies that all actions of this instance are time-out only after waiting for a period of time.
  2. Explicit Waits: This is an exclusive time-out method that works by adding code to delay the execution until a specific condition arises. It is more customizable in terms that we can set it up to wait for any suitable situation. Usually, we use a few of the pre-built expected conditions to wait for elements to become clickable, visible, invisible, etc.
  3. Fluent Waits: This defines the maximum amount of time to wait for a particular condition and frequency to test the condition before throwing an exception to “ElementNotVisibleException.”

9. What is the difference between WebDriver.findElement vs WebElement.findElement?

10. What are all the design patterns in the Selenium framework?

11. What is the difference between Page Object Model and Page Factory?

12. What are all the locators that support Selenium?

Name: Same as ID although it is not unique

CSS Selector: Works on element tags and attributes

XPath: Searches elements in the DOM. Reliable but slow

Class name: Uses the class name attribute

TagName: Uses HTML tags to locate web elements

LinkText: Uses anchor text to locate web elements

Partial Link Text: Uses partial link text to find web elements

13. What are the differences between XPath and CSS Selector?

14. How to access the CSS selector using the nth element?

Here is a syntax for using the CSS selector to access the nth attribute:  <type>:nth-child(n)

Ex:  tr:nth-child(2)

15. How can one handle alerts in Selenium WebDriver?

WebDriver provides an API to handle alert dialogs.  Alerts cannot able to inspect if there is no Alert in the screen, you will get ‘NoAlertPresentException’

The Alert interface contains a number of APIs to execute different actions, including: 

16. What are the exceptions in Selenium WebDriver?

17. How would you overcome StaleElementReferenceException in Selenium?

Because the reference to an element is now stale the element will no longer appear on the page’s DOM. In other words, the element you located using the findElement method disappeared. 

To resolve this, add exception handling to your action. If the exception is stale, locate the element after a short wait of 500 milliseconds and repeat these actions until the action or max iterations have been successful.

18. What is a framework? What are the different types of frameworks available?

A framework is a charter of rules and best practices for the systemic resolution of a problem. 

There are different kinds of automation frameworks:

19. How should one handle Windows-based alerts or pop-ups in Selenium?

Selenium only supports web applications and does not provide a way to automate Windows-based applications. However, the following approach can help.

Use the Java-based Robot class utility to simulate keyboard and mouse actions. The KeyPress and KeyRelease methods simulate the user pressing and releasing a specific key on the keyboard.

20. What are TestNG annotations frequently used with Selenium?

TestNG annotations prioritize the calling of a test method over others. Here are the ones to use with Selenium:

21. What are Listeners in Selenium?

Listeners is an interface that modifies the behavior of the system allowing customization of reports and logs.

There are two primary types of Listeners, WebDriver Listeners, and TestNG Listeners. 

22. What is a soft assertion and a hard assertion in Selenium?

Soft Assertion: A Soft Assert will not throw an exception when an assert fails and will continue with the next step.

Hard Assertion: A Hard Assert throws an Assert Exception immediately when an assert statement fails and test suite continues with next @Test.

23. What are static blocks or static initializers in Java?

Static blocks or static initializers are used to initialize static fields in java. We declare static blocks when we want to initialize static fields in our class. Static blocks are executed exactly once when the class is loaded. Static blocks are executed even before the constructors are executed.

24. How should you use the keywords This and Super in Java?

This: This keyword can only be used for the constructor. It initializes class level variables in the constructor using local variables. We can use more than one This Keyword within the Constructor at a time.

Super: Using Super keyword to call Parent class constructor. We can only have one Super keyword declared within the constructor at a time. You should always write Super keyword in child class constructor

25. Why is the main() method is public, static, and void in Java?

26. What are the differences between Method Overloading and Method Overriding in Java? 

Method OverloadingMethod Overriding
Method overloading occurs within the same classMethod overriding occurs between two classes superclass and subclass
Since it involves only one class, inheritance is not involvedSince method overriding occurs between superclass and subclass, inheritance is involved
In overloading, return type need not be the sameIn overriding, return type must be same
Parameters must be different for overloadingParameters must be same for overriding
Static polymorphism is achieved using method overloadingDynamic polymorphism is achieved using method overriding
In overloading, one method can’t hide the anotherIn overriding, subclass method hides the superclass method

27. What is an exception in Java?

In Java, exception is an object. Exceptions are created when an abnormal situation is raised in the program. Exceptions can be created by JVM or by our application code. All exception classes are defined in java.lang. In other words, we can see this as a runtime error.

28. What are the differences between interface and abstract class?


1) Interface contains only abstract methods 

2) Access Specifiers for methods in interface must be public

3) Defined variables must be public, static, final

4) Multiple Inheritance in Java is implemented using interface

5) To implement an interface, use the implements keyword

Abstract Class:

1) Abstract class can contain abstract methods, concrete methods, or both

2) Except with private variables, we can have any access specifier for methods in abstract class

4) We cannot achieve multiple inheritance using abstract class.

5) To implement an interface we use implements keyword

29. How would you explain the  ‘try’ and ‘catch’ keywords in Java?

In a try block, we define all exceptions causing code. In Java, try and catch forms a unit. A catch block catches the exception thrown by the preceding try block. Catch block cannot catch an exception thrown by another try block. 

If there is no exception causing code in our program or an exception is not raised in our code, Java Virtual Machine ignores the try catch block.

try {
catch(Exception e)

30. What is the importance of the ‘finally’ block in Java?

The finally block is used for cleaning up resources such as closing connections and sockets. If the try block executes with no exceptions, then finally is called after try block without executing a catch block. 

If there is exception thrown in the try block, finally block executes immediately after catch block. If an exception is thrown, finally block will be executed even if the no catch block handles the exception.

Page Last Updated: December 2020

Selenium WebDriver students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.

Request a demo