100+ Top Selenium Interview Questions for 2023

Selenium WebDriver is one of the best automation testing tools in recent years. Therefore, in the IT industry, the demand for Selenium WebDriver based jobs is growing rapidly day by day in the market.

Here, we have listed the best collection of frequently asked Selenium WebDriver Interview Questions with the best possible answers to crack the interviews.

We have also covered the most basic Selenium WebDriver interview questions and answers that will be helpful for freshers.

You can also prepare answers of Java interview questions for Selenium automation testing from basic to advanced.

Frequently Asked Interview Questions in Selenium Basic


1. What is Automation Testing?

Ans: Automation testing is a process of automating manual processes to test applications or systems. It uses separate testing tools in which test script is created and executed repeatedly.

2. What are the benefits of Automation testing?

Ans: There are the following benefits of automation testing. They are as follows:

  • Automation testing supports the execution of repeated test cases.
  • It supports parallel execution.
  • It helps to improve accuracy and reduces human-generated error.
  • It saves time and money.

3. What is Selenium? What are the different components of selenium?

Ans: Selenium is a free and open-source browser automation testing tool which is used to test the functionality of web based application. It supports different operating systems and different languages. It is originally developed by Jason Huggins in 2004.

There are four components available in selenium suite to automate the web application.

  • Selenium IDE (Integrated Development Environment)
  • Selenium Remote Control (RC)
  • WebDriver
  • Selenium Grid

4. Why should Selenium be selected as a testing tool?

Ans: There are the following reasons to select selenium as a testing tool.

  • Selenium is free and open-source.
  • It supports different operating systems like Windows, Mac OS, and Linux.
  • It supports different programming languages such as Java, C#, Python, Perl, Ruby, and PHP. We can code in Java, Python, C#, etc.
  • It supports almost all popular browsers like Chrome, Firefox, Opera, IE, etc.
  • Selenium supports cross-browser compatibility (Chrome, Firefox, or IE).

5. What is Selenium 1.0?

Ans: Selenium 1.0 or Selenium Remote Control (popularly known as Selenium RC) is a freeware automated testing tool that allows testers to test web-based applications.

It was developed to extend framework in multiple programming languages. It is composed of Selenium IDE, Selenium Core, Selenium RC, and Selenium Server.

6. What is Selenium 2.0?

Ans: Selenium 2.0 (also known as WebDriver) is the latest, free, and open-source library to automate web applications. It is a pure object-oriented tool.

This powerful tool was developed in 2008 when Selenium RC was merged with another testing framework called WebDriver.

7. What are the types of testing supported by selenium?

Ans: Selenium supports different types of testing. They are as follows:

  • Functional Testing
  • Regression Testing
  • Retesting
  • Acceptance Testing
  • End-to-End Testing
  • Smoke Testing
  • Sanity Testing
  • Responsive Testing
  • Cross Browser Testing
  • UI Testing
  • Integration Testing

8. What are four parameters that have to pass in Selenium?

Ans: Four parameters that have to pass in selenium, are Host, Port Number, Browser, and URL.
[adinserter block=”5″]
9. What are the limitations of Selenium?

Ans: There are the following limitations of Selenium. They are:

  • Selenium supports the testing of only web applications.
  • Captcha and barcode cannot be tested by using selenium.
  • Mobile applications cannot be tested by using Selenium.
  • Test reports can only be generated using third-party tools like JUnit or TestNG.

10. What is the difference between Selenium and QTP?

Ans: There are several differences between Selenium and QTP. They are:

a) Open/Licensed: Selenium is free and open-source whereas, QTP is a licensed tool.

b) Operating system: Selenium supports various operating systems like Windows, Mac OS, and Linux whereas, QTP supports only Windows operating systems.

c) Browser: Selenium supports almost all types of browsers like Firefox, Chrome, IE, Opera, Safari, etc whereas, QTP supports only IE.

d) Testing: Selenium supports only testing web-based applications while QTP can be used for testing of both web-based and window-based applications.

e) Programming language: Selenium supports multiple programming languages like Java, C#, Python, Ruby, etc while QTP supports only VB script.

f) Object repository: Object repository needs to be created in selenium whereas QTP automatically creates and maintains object repository.

Interview Questions based on Selenium WebDriver


1. What is Selenium WebDriver?

Ans: Selenium WebDriver is a web automation framework that executes tests against different browsers like Firefox, Chrome, IE, etc.

It allows the users to create test scripts in different programming languages. It was designed by Simon Stewart while he was working at ThoughtWorks.

2. Is WebDriver interface or class?

Ans: WebDriver is a public interface, not a class. We just define a reference variable (driver) of type WebDriver interface. Now, we can assign an instance of a class (such as FirefoxDriver class) that implements WebDriver interface to use methods provided by WebDriver.

For example:

WebDriver driver = new FirefoxDriver();

3. How WebDriver is an interface?

Ans: Creating WebDriver as an interface is the best way to expose a set of APIs that will provide a lot of capabilities to the Selenium tool. Selenium developers knew that logic will not be the same for all browsers.

Interface is a mechanism that has only abstract methods i.e methods that have no body or logic. Therefore, WebDriver interface allows users to write their logic in abstract methods provided by WebDriver.

RemoteWebDriver class implements WebDriver interface which is extended by Browser drivers.

4. How Selenium WebDriver works?

Ans: Selenium WebDriver works in three steps. They are as follows:

Selenium WebDriver working, Selenium Interview Questions

a. The first step is to send commands (programming code and selenese commands) to the Selenium WebDriver server via commands line associated with selenium server.
[adinserter block=”2″]
b. In the second step, Selenium WebDriver Server sends Javascripts commands to Web Browser Driver. The interaction from Selenium WebDriver server to driver elements of web browser is done with the help of Javascript Libraries.

c. In the third step, Selenium Web browser driver elements interact with web application using commands from selenium to perform actions of users like entering text, clicking on button, etc.

5. What is the name of super interface of WebDriver?

Ans: SearchContext is the super interface of Webdriver. It is the top most interface in selenium, which is extended by another interface called WebDriver. It has only two methods named findElement() and findElements().

6. What is RemoteWebDriver?

Ans: RemoteWebDriver is a class that extends object class and implements WebDriver, and JavascriptExecutor interfaces.

7. What are Programming Languages supported by Selenium WebDiver?

Ans: Selenium WebDriver supports multiple programming languages like Java, C#, Python, Ruby, Perl, and PHP. We can write code in any of these languages.

8. What are Operating Systems supported by Selenium WebDriver?

Ans: Selenium WebDriver supports multiple operating systems such as Windows, Linux, Mac OS, IOS, and Android.

9. How many types of WebDriver APIs are available in Selenium?

Ans: There are several types of WebDriver APIs available in Selenium WebDriver. They are FirefoxDriver, GeckoDriver, InternetExplorerDriver, ChromeDriver, HTMLUnitDriver, OperaDriver, SafariDriver, AndroidDriver, iPhoneDriver, and EventFiringWebDriver.

10. What are testing frameworks supported by Selenium WebDriver with Java?

Ans: Selenium WebDriver with Java supports two testing frameworks such as JUnit and TestNG.

11. Is FirefoxDriver a class or an interface? 

Ans: FirefoxDriver is a Java class that implements a WebDriver interface.

12. How do we launch a web browser by using Selenium WebDriver?

Ans: WebDriver is an Interface. We create an object of a required driver class such as FirefoxDriver, ChromeDriver, InternetExplorerDriver, etc by assigning WebDriver reference. For example:

a. To launch Firefox Driver:

WebDriver driver = new FirefoxDriver()

b. To launch Chrome Driver:

WebDriver driver = new ChromeDriver();

c. To launch Internet Explorer Driver;

WebDriver driver = new InternetExplorerDriver();

13. Why do we assign Firefox instance to WebDriver reference such as WebDriver driver = new FirefoxDriver();?

Ans: We assign the FirefoxDriver object to WebDriver reference because it allows assigning driver object with different browser drivers.

If we want to switch other browsers in the same program for multiple browser testing, we will have to create multiple objects for different browsers that are the worst kind of programming. Therefore, we create a WebDriver reference and assign an object of class.

14. What is difference between WebDriver and FirefoxDriver?

Ans: WebDriver is an interface whereas, FirefoxDriver is a class that implements WebDriver interface.

15. How to write test cases using Selenium WebDriver?

Ans: We can write test cases using element Locators, Selenium WebDriver methods, and Java programming features. Element locators are used to locating WebElements on the web page.

Selenium WebDriver methods are used to perform operations on WebElement. Java is used to enhance programming features.

There are five basic steps to write test cases that can be applied to any test case and any application under test (AUT). They are as follows:

  • Create a WebDriver instance.
  • Navigate to a Web page.
  • Locate an HTML element on the Web page using locators.
  • Perform an action on an HTML element.
  • Run tests.

16. What is Firebug?

Ans: Firebug is a Firefox addon which is used to inspect HTML web elements on the web page during a test.

17. What are the limitations/drawbacks of WebDriver?

Ans: There are many limitations or drawbacks of WebDriver. They are:

a. Selenium WebDriver can be used only to test web-based applications. We can not test Windows-based applications or desktop applications and any other software.
b. It is not possible to perform the testing on the image.
c. WebDriver does not generate automatically test result files.
d. WebDriver cannot support new browsers.

18. Which WebDriver implementation is the fastest?

Ans: HTMLUnit Driver is the fastest WebDriver implementation.

19. What is HTMLUnitDriver in Selenium?

Ans: HTMLUnitDriver is the fastest and most lightweight web browser for implementation of WebDriver. It has no GUI (Graphical User Interface).

Since, in HTML unit driver, test runs in the background without any visual interruption, we cannot see test execution on the screen. Hence, test execution becomes faster than other drivers.

20. What is the difference between HTMLUnitDriver and FirefoxDriver?

Ans: There are following differences between HTMLUnitDriver and FirefoxDriver.

  • HTMLUnitDriver is a lightweight web browser whereas, FirefoxDriver is a heavyweight browser.
  • HTMLUnitDriver has no plugin whereas, FirefoxDriver has plugin.
  • HTMLUnitDriver does not GUI whereas, FirefoxDriver has.
  • In the HTMLUnitDriver, test execution is fast whereas, slow execution happens in the FirefoxDriver.

21. What are the differences between Selenium IDE, Selenium RC, and WebDriver?

Ans:

Selenium IDE:

  1. Selenium IDE is a Firefox plugin that supports only Firefox.
  2. It is a Javascript-based framework.
  3. It is not an object-oriented tool.
  4. Selenium IDE supports record and playback features.
  5. Selenium IDE does not need any server to be started before executing the test script.
  6. It does not support dynamic finders and listeners.
  7. Selenium IDE does not support the testing of Andriod/iPhone applications.

Selenium RC:

  1. Selenium RC supports various types of browsers like Mozilla Firefox, Google Chrome, Internet Explorer and Opera.
  2. It is a Javascript-based framework.
  3. Selenium RC is a semi-object-oriented tool.
  4. It does not support record and playback feature.
  5. Selenium RC requires server to be started before executing the test scripts.
  6. Selenium RC also not support dynamic finder and listener.
  7. Selenium RC does not support the testing of iPhone/Android applications.

WebDriver:

  1. WebDriver supports almost all popular browsers like Mozilla Firefox, Google Chrome, Internet Explorer, Opera, etc.
  2. It is a pure object-oriented tool.
  3. It does not support record and playback features.
  4. It does not need any server to be started before execution of test scripts.
  5. WebDriver supports dynamic finders and the implementation of listeners.
  6. WebDriver is faster than Selenium RC.
  7. WebDriver supports testing of iPhone/Android applications by the available tool.

Interview Questions based on Selenium WebDriver Commands


1. How to open a Website using Selenium WebDriver?

Ans: The get() method is used to open the specified URL in the current browser window. The URL must be in the form of http://www.xyz.com.

If the HTTP is not included then it will throw a message “Cannot navigate to invalid URL”. The syntax is as follows:

WebDriver driver = new FirefoxDriver();
    driver.get("https://www.xyz.com")

2. How to click on a button on the web page?

Ans: click() method is used to click on a button on the web page. The syntax is given below:

driver.findElement(By.id("submit")).click();

3. How to get Page Title of web page using Selenium WebDriver?

Ans: getTitle() method of WebDriver is used to get page title of any web page. The syntax is as follows:

String pageTitle = driver.getTitle();
   System.our.println(pageTitle);

4. How to get a text from a specified element or object on web page?

Ans: The getText() method is used to retrieve inner text of specified element on web page. The syntax is given below:

driver.findElement(By.locatorName("Specified Element")).getText();

5. How to compare page title on web page with expected title in Selenium WebDriver using Java?

Ans: We will verify or compare the title of the web page in Selenium WebDriver using the String concept of Java. Let’s see the main source code.

String actualTitle = driver.getTitle(); 
String expectedTitle="Facebook – log in or sign up"; // Use equalsIgnoreCase() method of String class to verify actual title with expected title. 

if(actualTitle.equalsIgnoreCase(expectedTitle)) { 
  System.out.println("Verification is success" ); 
  System.out.println("Home page title is:" + actualTitle ); 
 } else { 
    System.out.println("Verification is failed, Matched not found"); 
 }

6. What is the difference between driver.get() and driver.navigate() method?

Ans: The difference between get() and navigate() methods of Selenium WebDriver are as follows:

a) The driver.get() method is used to open a specified URL of web application and wait until the whole page gets loaded whereas,

driver.navigate().to() method is used to navigate a specified URL of web application and it does not wait till the whole page gets loaded.

b) driver.get() method does not maintain the browser history and cookies whereas, driver.navigate() method maintains the browser history and cookies.

c) We can not go forward or backward between the pages using the driver.get() whereas, we can easily navigate between the pages forward, back, and refresh using driver.navigate().

7. What is the difference between close and quit methods of Selenium WebDriver?

Ans: The close() method is used to close only the browser window that WebDriver is currently controlling whereas, the quit() method is used to close all windows opened by WebDriver.

8. What are Navigation commands in Selenium WebDriver?

Ans: Navigation commands are those commands in Selenium that are used to perform different operations such as backward, forward, refresh, wait, etc in the browser’s history.

The navigation commands available in Selenium WebDriver are back, forward, refresh, navigate, and to.

9. How to move forward and backward on the web page?

Ans: forward() method is used to move forward by one page on the browser’s history.

back() method is used to move back by one page on the browser’s history.

10. What is WebElement? Is WebElement class or interface?

Ans: The elements that are present on a web page are called WebElement. It represents an HTML element. Text boxes, links, buttons, dropdown buttons, radio buttons, labels, and forms are called WebElement. It is an interface.

11. How many methods have been provided by Selenium WebDriver to find WebElement?

Ans: There are two methods available in Selenium WebDriver to find WebElement.

a. findElement(): This method is used to locate one web element in the current web page using the locator provided in the parameter list.

b. findElements(): This method is used to find a list of web elements (i.e. multiple elements) on the current web page using the locator provided in the parameter list.

12. What is the return type of findElement and findElements?

Ans: The return type of findElement() method is a WebElement object whereas, findElements() method returns a list of WebElements.

13. Which input parameter does findElement() method take?

Ans: The findElement() method takes an input parameter of type By. By is an instance of By class.

14. Which exception is thrown by WebDriver when it is unable to find an element on web page?

Ans: Runtime exception named NoSuchElementException.

15. What is the difference between findElement and findElements?

Ans: Refer to answer 11 and 12.

16. How will you find more than one WebElement on the list?

Ans: findElements() method of WebDriver can be used to find more than one web element and save them into a list.

17. How to clear text in the text box using Selenium WebDriver?

Ans: The clear( ) method provided by Selenium WebDriver is used to clear the text entered or displayed in the text box.

18. How to submit a form using Selenium WebDriver?

Ans: The submit() method is used to submit a form with <form> tag. It accepts nothing as a parameter and returns nothing. It will throw NoSuchElementException if the current element is not present within a form.

19. How to send user input in the text box using Selenium WebDriver?

Ans: The sendKeys() method of Selenium WebDriver is used to type or send text input in the text box. It accepts text or any sentence as a parameter and returns nothing.

20. How will you identify/verify that element is present/displayed/visible on the web page or not?

Ans: Selenium WebDriver provides a method isDisplayed() that can be used to check the visibility of the certain element on web page.

This method will return true if the element is present on the web page. Otherwise, it will throw NoSuchElementFound exception if the element is not present on the page.

21. How to verify whether a certain element is present on web page or not?

Ans: The isEnabled() method is used to check or verify whether a certain element is enabled or not on web page.

22. How to verify whether checkbox, radio button or option in the drop-down is selected on web page or not?

Ans: The isSelected() method is used to verify whether a certain checkbox, radio button, or option in the drop-down box is selected or not. It takes nothing as a parameter and returns a boolean value.

FAQs on Selenium Locators


1. What is locator in Selenium? What is the use of locators in Selenium WebDriver?

Ans: Locator in selenium is like an address that is used to identify the web element uniquely within the web page.

The basic use of locators is to identify the element or object on the webpage accurately. Selenium WebDriver uses locators to interact with elements present in a web page.

2. What are the types of locators available in Selenium WebDriver?

Ans: There are eight types of locators to locate an element on the web page. They are as follows:

  • ID locator
  • Name locator
  • ClassName locator
  • TagName locator
  • LinkText locator
  • Partial LinkText Locator
  • CSS Selector
  • XPath

For more details, go to this tutorial: Locators in Selenium WebDriver

3. Which is the best locator in Selenium WebDriver? 

Ans: ID locator is king! It is the safest and fastest locator in Selenium WebDriver. It should always be your first choice.

4. There is ID, name, CSS, or XPath locator, which one should I use?

Ans: If there is a constant ID/name available, you should be used instead of CSS and XPath locator. If not, the CSS locator should be used instead of XPath because it is faster than XPath in the modern browser.