Interviewing for a Selenium Testing Job? Here Are the Top 10 Questions You Need to Know

Are you preparing for an upcoming interview for a Selenium testing job? With the growing demand for Selenium testers, it’s important to have a thorough understanding of the key concepts and skills required for the role. In this article, we will provide you with a comprehensive list of the top 10 Selenium interview questions that are commonly asked in interviews. We’ll cover topics such as Selenium WebDriver, test automation, test frameworks, and more

The two commands driver.quit() and driver.close() are basically used to close a browser window/session. Here is a detailed explanation about each of the command:

  1. driver.quit() is a command that closes the complete webdriver session . It will close all the popups , tabs and releated windows irrespective of the window in focus.
  2. driver.close() is a command that closes only the particular window which is in focus. If there is only one window then it closes the entire webdriver session.

2. Difference between driver.naviagte().to() and driver.get()?

The two commands driver.navigate().to() and driver.get() are basically used to the same operation that is to open a webpage and navigate to a particular URL. Here is a detailed explanation about each of the command:

  1.  driver.get() is a command that helps us navigate to a particular URL . This command waits for the entire webpage to load before returning the control back . The only drawback with this method is that it does not store the browser history and cookies.
  2. driver.navigate().to() is also a command that helps us navigate to a particular URL . Unlike driver.get() the navigate() method creates instance of the Navigation class which provides us with additional functionalities such as navigate.refresh(),navigate.back(),navigate.forward() etc . In simple terms it can store the browser history as well.

It Should be noted that behind the scenes is using the driver.get() method itself.

3. What are the different exceptions that can occur in Selenium ?

Exception : Exception is a unwanted event or issue that occurs during the execution of a program which disturbs the normal flow of program’s steps.

These are the most common exceptions that can occur during execution of a selenium program:

  1. NoSuchElement Exception
  2. Stale Element Reference Exception
  3. Element Click Intercepted Exception
  4. ElementNotVisible Exception
  5. NoSuchFrame Exception
  6. NoAlertPresent Exception
  7. NoSuchWindow Exception
  8. SessionNotFound Exception

4. What are the different ways in which waits can be added in Selenium?

There are basically three different types of waits that selenium library provides us with. Here is a detailed description about them :

Implicit Wait: Implicit wait in selenium is wait that informs the webdriver to wait for a certain period of time for webelement before throwing a “NoSuchElement Exception”.


Explicit Wait: Explicit wait in selenium is wait that informs the webdriver to wait till a expected condition for a web element before throwing a “Element Not Visible Exception”. This type of wait is mainly used for dynamically loaded webpages.

					WebDriverWait wait = new WebDriverWait(driver,10);

Fluent Wait: Fluent wait in selenium is also considered to be a type of explicit wait .The only difference between explicit and fluent wait is that unlike in explicit wait in fluent wait this wait informs the webdriver to check for a expected condition with a certain frequency until a particular timeout occurs. 

					Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(10, TimeUnit.SECONDS) 	
.pollingEvery(2, TimeUnit.SECONDS)

5. How do handle dropdowns in Selenium?

In Selenium basically we usually encounter select based dropdowns . These type of dropdowns are handled using the select class from the selenium package.

The select class is a ordinary class but to handle select dropdowns in Selenium, you can use the Select class provided by the Selenium WebDriver. The Select class provides methods to interact with dropdown elements, such as selecting options by their visible text, value, or index, as well as deselecting options.

					// Create a new instance of the Select class
Select dropdown = new Select(driver.findElement(By.xpath("//div[@class='ui dropdown']"));

// Select an option by visible text

// Select an option by value attribute

// Select an option by index (0-based)


6. What is Actions class in Selenium?

Actions class is  a special class provided by Selenium library which is used to provide us unique methods such as keyboard and mouse actions on the web elements such as double click , context click , drag and drop a element and much more. Using Actions and action we can chain multiple actions together in a sequence.


					#Create a instance of Action class
Actions act = new Actions(driver);
#Instantiate a action using the above actions object
Action btnClick = act.contextClick(By.xpath("//div[@class='entry-content single-content']")).build();
#Perform the Action

7. what is a XPath and what are the types of XPaths in Selenium?

XPath (XML Path Language) is a powerful language used to navigate through XML documents and identify elements in an XML structure. In the context of Selenium, XPath is widely used to locate elements on a web page. It provides a way to traverse the HTML structure and identify elements based on their attributes, tags, text content, or relative position in the document

Using XPath all the different elements in the webpage are located and the related selenium operations are done on them.

All the XPaths can be categorized into the following two categories:

  1. Absolute XPath
  2. Relative XPath

8. How are IFrames dealt in Selenium?

Iframe is a inline html code or webpage of a different webpage in the current webpage. These iframes are added to the current page using a <iframe> tag . These iframes are usually used to display ads or videos . 

In order to test these or do some selenium operations on these iframes we need to switch to this iframe just like we switch window or tabs. In selenium there are three ways in which we can switch to a iframe.

  1. By using iframe id 
  2. By using iframe name
  3. By using iframe web element

If we want to switch back to the parent frame or default context we can follow the below two commands to do the operation.



9. Explain the concept of headless browser testing in Selenium?

Headless browser in simple terms is basically a browser object with no User Interface or GUI . Using Headless mode we can test the browser by controlling it programmatically without the UI shown to the user .This type of testing is very helpful when you have to test multiple windows at once or run the test cases at a much faster pace. It should be noted that just like in normal UI testing every actions such as clicking a button , downloading files etc. are done behind the scenes without UI. 

10. What is the difference between getWindowhandles() and getwindowhandle()?

Here is a detailed description on getWindowHandle() and getWindowHandles() methods and what they are used for:

  1. driver.getWindowHandle() – getWindowHandle() is a method that basically fetches the handle of the window in focus which is a unique identifier. The return type of this method is a string. It is used to get the address of the current browser.
  2. driver.getWindowHandles() –  getWindowHandles() is a method that basically fetches the handles of all the open pages simultaneously.The return type of this method is a Iterator<string>.It is used to get all addresses of the open browsers.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.