20 Selenium Interview Questions and Answers | OdinSchool

20 Selenium Interview Questions and Answers | OdinSchool


This blog provides a comprehensive guide to Selenium interview preparation, offering a list of common interview questions and answers for Selenium Automation Testing. It emphasizes the importance of skills such as test architecture, design, performance testing, and communication for aspiring Selenium Automation Testers. The article covers essential Selenium components like Selenium IDE, Selenium Grid, and Selenium RC/WebDriver. It explains key concepts like assert and verify commands, element location methods, testing types, and JUnit annotations. The distinction between Page Object Model (POM) and Page Factory is highlighted, along with details about handling web-based pop-ups, taking screenshots, and using the Robot class in Selenium. Differences between Selenium and QTP are also outlined, concluding with valuable insights for Selenium interview success.

Table of Content

We all know that job interviews can be challenging, especially if you don’t have all the information in one place.  Moreover, preparing for an interview takes a lot more than Googling a list of common interview questions.

But don’t worry we have chalked down some Selenium interview questions and answers that can save your time and effort.

Also, in case you are looking to get hired for Selenium Automation Testing, then you should have the following skills:

  • Test architecture
  • Test design
  • Performance testing
  • Configuration management
  • Manual testing agility & interaction
  • Communication between teams
  • Troubleshooting
  • Agile, DevOps, and continuous delivery

Selenium interview questions

1. Please explain the various Selenium components

Selenium IDE- It is a tool for recording and playing back. You can also call it a firefox plugin.

Selenium Grid- It is the best way to run parallel testing on multiple machines. The grid helps you in distributing tests while making sure that you save time in performing them on running in-browser test suites. 

Selenium RC and WebDriver – It is a server that allows users to create test scripts in a desirable programming language like Java, .NET, PHP, etc. Also, remember that with most of the browsers Webdriver and RC work. 

2. Can you explain the difference between assert and verify commands in Selenium?

Though both assert and verify commands checks whether the given condition is true or false. But one of the basic differences between the two lies after the condition checking is complete.

For instance, if a particular condition comes out to be false in the case of an assert, then the execution stops there only, and no further tests will be done. But if the condition is true then the program control will move to the next test step.

Whereas on the other hand Verify command, does not care about the result of the condition checking. Whether it is true or false, the program will be completed.

3. How will you find an element using Selenium?

There are different ways to find an element in a web page using Selenium: 

  • ID
  • Name
  • Tag
  • Attribute
  • CSS
  • Linktext
  • PartialLinkText
  • Xpath 

4. What are the testing types that can be supported by selenium?

Testing types that can be supported by Selenium are as follows:

  • Functional Testing
  • Regression Testing
  • Sanity Testing
  • Smoke Testing
  • Responsive Testing
  • Cross Browser Testing
  • UI testing (black box)
  • Integration Testing

5. What is the syntax used to launch the browser using WebDriver?

The syntax used for launching any browser like Google Chrome, Mozilla Firefox, and Internet Explorer using WebDriver is: 

new WebDriver driverDriver();

6. How will you find an element on the screen? 

With the help of WebDriver we can easily find out any element on the screen. And we can do this with the following 3 methods:

  • isDisplayed() boolean buttonPresence = driver.findElement(By.id(“some id”)).isDisplayed();
  • isEnabled() boolean searchIconEnabled = driver.findElement(By.id(“some id”)).isEnabled();
  • isSelected() boolean buttonSelected = driver.findElement(By.id(“some id”)).isSelected();

7. What are the four parameters you have to pass in Selenium?

The four parameters that you have to pass in Selenium are:

  • Host
  • Port Number
  • Browser
  • URL

8. How can you “submit” a form using Selenium?

With the help of the Webdriver software testing tool, one can easily submit any form. Just type element.submit(); or you can use click() method to click on any button of the software web application.

9. What is the difference between type keys and type commands?

Type keys Simulates keystroke events on the specified element, as though you typed the value key-by-key.

This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string; this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events. Type key populates the value attribute using JavaScript

Type command is mainly used to type text into the text box and text area fields. Type command forces the specified value into the page directly. 

This command may or may not have any visible effect, even when typing keys normally have a visible effect. For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in the field.

10. When should we use findElement() and findElements()?

findElement method is used to access a single web element on a page. It returns the first matching element. It throws a NoSuchElementException exception when it fails to find If the element.

findElements method returns the list of all matching elements. This method returns an empty list when the element is not available or doesn’t exist on the page. It doesn’t throw NoSuchElementException.

11. What are JUnit Annotations and what are different types of annotations which are useful?

JUnit is a Java-based, open-source framework to help you execute unit testing. JUnit is used primarily to test each and every unit or component of your application like classes and methods. It helps to write and run repeatable automated tests, to ensure your code runs as intended. The framework offers support to Selenium for automation testing web-apps or websites.

@BeforeClass: This annotation is used to initialize any object that we use in our running test case. Used to execute some statements before all the test cases mentioned in the script.

@Before: This annotation is used whenever we want to initialize an object for the time the method is being used. This annotation is usually used for setting up the test environment.

@Test: This annotation tells JUnit that the public void method() to which it is attached can be run as a test case. This annotation includes the test method for an application that you want to test.

@After: The initialization done in the @Before annotation method should be released in the @After annotation method. So, this annotation is executed every time after each test method. The primary purpose of @After annotation is to teardown. The teardown is a process of deleting temporary data.

@AfterClass: The initialization done in the @BeforeClass annotation method should be released in the @AfterClass annotation method. So, this annotation is executed once but it will be executed after all tests have finished executing.

@Ignore: This annotation tells JUnit that this method shall not be executed. In scenarios, where our code module is not ready in a particular test case, we can temporarily put that code module in the @Ignore annotation method to avoid test case failure.

12. What is POM (Page Object Model)? What are its advantages?

POM is a design pattern used for enhancing test maintenance and reducing code duplication. 

A page object is an object-oriented class that serves as an interface to a page of your application under test. The tests then use the methods of this page object class whenever they need to interact with the User Interface (UI) of that page. 

The benefit is that if the UI changes for the page, the tests themselves don’t need to change, only the code within the page object needs to change. Subsequently, all changes to support that new UI are in a single place.

Advantages of the Page Object Model Framework:

  • Code reusability – Achieve code reusability by writing the code once and use it in different tests
  • Code maintainability – There is a clean separation between test code and page specific code such as locators and layout which becomes very easy to maintain code. Code changes only on Page Object Classes when a UI change occurs. It enhances test maintenance and reduces code duplication
  • Object Repository – Each page will be defined as a java class. All the fields in the page will be defined in an interface as members. The class will then implement the interface
  • Readability – Improves readability due to clean separation between test code and page specific code

13. What is the difference between Page Object Model (POM) and Page Factory?

Page Object is a class that represents a web page and holds the functionality and members. Page Object Model is a way of representing an application in a test framework. For every page in the application, we create a Page Object to reference the page.

Page Factory is a way to initialize the web elements you want to interact with within the page object when you create an instance of it. Page Factory is one way of implementing the Page Object Model.

14. What are the different types of WAIT statements in Selenium WebDriver?

Implicit wait: Directs the WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs.

Explicit Wait: The WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. It is important in cases where there are certain elements that naturally take more time to load.

15. Explain the various types of navigation commands supported by Selenium?

  • navigate().back() – This method enables the web browser to click on the back button in the existing browser window. It neither accepts anything nor returns anything. 
  • navigate().forward() – This method enables the web browser to click on the forward button in the existing browser window. It neither accepts anything nor returns anything
  • navigate().refresh() – This method refreshes/reloads the current web page in the existing browser window. It neither accepts anything nor returns anything.
  • navigate().to() – This method loads a new web page in the existing browser window. It accepts string as a parameter and returns void.

16. How will you handle web-based pop-ups in Selenium?

WebDriver allows handling web-based pop-ups via the Alert interface. The general syntax is:

Alert alert = driver.switchTo().alert();


A total of 4 methods are available for handling the web-based pop-ups, namely:

  • String getText() – This method returns the text displayed on the alert box.
  • void accept() – This method clicks on the “Ok” button as soon as the pop-up window appears.
  • void dismiss() – This method clicks on the “Cancel” button as soon as the pop-up window appears.
  • void sendKeys(String stringToSend) This method enters the specified string pattern into the alert box.

17. How to take screenshots in Selenium WebDriver?

Screenshot can be taken using the TakeScreenshot function

By using the getScreenshotAs() method you can save that screenshot.

Example: File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

18. What is the difference between “/” and “//”?

Single Slash “/” – Single slash is used to create XPath with absolute path i.e. the XPath would be created to start selection from the document node/start node.

Double Slash “//” – Double slash is used to create XPath with a relative path i.e. the XPath would be created to start selection from anywhere within the document.

19. Can you explain the differences between Selenium and QTP?

Below are some parameters listing the differences between Selenium and QTP

  • Availability – Selenium is an open-source and free-to-use testing tool while QTP is a licensed and commercial testing tool.
  • Browser Compatibility – QTP provides support for only Chrome, Firefox, and Internet Explorer while Selenium can be used with the aforementioned plus Opera, Safari, and several others.
  • Object Repository – QTP automatically creates and maintains an Object Repository. While Selenium needs to create an Object Repository while working with the automation testing tool.
  • Programming Language Support – The only programming language supported by QTP is VB but Selenium provides support for multiple programming languages, including C#, Java, Perl, Python, and Ruby.
  • Testing Support – Selenium offers to test for only web applications, while QTP provides testing support for both web-based and Windows-based applications.
  • Vendor Support – No vendor support is available with Selenium while the support is available for QTP.

20. What is the Robot class in Selenium?

A Robot class in Selenium is used to generate input events for test automation, self-running demos, and other applications where you need control over the mouse and keyboard.  

WebDriver cannot handle OS pop-ups, so in Java 1.3, the Robot class was introduced. The primary purpose of this Robot class is to facilitate automated testing for Java platform implementations and to provide control over mouse and keyboard devices.


Full Stack Developer Course

About the Author

Meet Prerna Sharma, a talented writer who enjoys baking and taking pictures in addition to contributing insightful articles. She contributes a plethora of knowledge to our blog with years of experience and skill.

Join OdinSchool's React Web Development Course

With Job Assistance

View Course