Learning Path for Programming Journey. Start Now

20 Most Important Selenium Interview Questions

Selenium Interview Questions


Spread the Knowledge

Every aspiring tester, especially one aiming to work with web-based applications, must have a good knowledge about Selenium. This is because whenever applying for some job opportunity regarding web-based testing these days, expect Selenium-based questions coming your way.

Written completely in Java, Selenium is one of the most widely used automation testing tools. It is easy to use, simple and provides support for writing test scripts in a wide variety of programming languages, including C#, Groovy, Java, Perl, and Python.

Selenium Interview Questions

Here, we have collected 20 of the most important Selenium interview questions that will help you append your extant Selenium knowledge as well as check how well you fare against an array of Selenium interview questions thrown right at you. So, let’s jump right into it:

Q: Please explain the various Selenium components.
A: Although labeled as an automation testing tool, Selenium isn’t a standalone tool. Instead, it is a package of several tools, and thus a testing suite. The Selenium suite has the following components:

  • Selenium IDE – Distributed as a Firefox plugin, Selenium IDE serves as a record and playback tool.
  • Selenium Grid – Allows distributing test execution across multiple platforms and environments concurrently.
  • Selenium RC – A server that allows users to create test scripts in a desirable programming language. Selenium RC also permits executing test scripts across a diverse range of web browsers.
  • Selenium WebDriver – Communicated directly with the web browser in addition to using its native compatibility to automate.

Q: Could you state the limitations of Selenium?

  • Although Selenium has an active community support, no vendor support is available
  • No built-in report generation. Third-party tools like JUnit and TestNG need to be used
  • Not able to offer testing for barcode and captcha readers
  • Requires good programming language knowledge
  • Supports testing of only web-based applications. Hence, doesn’t provide support for testing mobile applications

Q: What are the different types of locators in Selenium?
A: A locator is a kind of address that offers a unique way of identifying a web element in the webpage. Selenium has a range of locators to identify different elements of a webpage, namely:

  • ClassName
  • CSS Selector
  • DOM
  • ID
  • LinkText
  • Name
  • PartialLinkText
  • TagName
  • XPath

Q: Can you explain the difference between assert and verify commands in Selenium?
A: Both assert and verify commands are responsible for checking whether the given condition is true or false. However, the main distinction between the two lies what each of them does after the condition checking is complete.

If the condition comes out to be false in the case of a verify command, then the execution stops and no further tests will be executed. However, if the condition is true then the program control will continue executing the next test step.

Verify command, on the other hand, does not care about the result of the condition checking. Whether it is true or false, the program execution continues and all the test steps will be completed.

Q: What do you understand by XPath in Selenium? Can you tell the difference between “/” and “//” in XPath?
A: XPath is a type of locator in Selenium that is used to locate a web element based on its XML path. XML denotes Extensible Markup Language, which is used for storing, organizing, and transporting arbitrary data. Much like HTML tags, XML stores data in a key-value pair.

Since HTML and XML both are markup languages, XPath can be used for locating HTML elements in a webpage. The underlying principle of XPath is traversing between several elements across the entire webpage and allowing to find an element with the reference of some other element.

The single slash i.e. ‘/’ is used to create XPath with the absolute path, while the double slash i.e. ‘//’ is used for creating XPath with the relative path.

In the absolute path, the created XPath will start selection from the document node or the start node. However, in the relative path, the created XPath can start selection from anywhere within the entire web document.

Q: How will you launch the browser using WebDriver?
A: The syntax used for launching Google Chrome, Mozilla Firefox, and Internet Explorer using WebDriver is respectively,

  • WebDriver driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();

Q: Please explain how to find if an element is displayed on the screen.

A: The WebDriver component of the Selenium suite facilitates checking the visibility of web elements, which can be buttons, checkboxes, drop boxes, labels, radio buttons, et cetera. WebDriver allows doing so with the following three 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();

Q: What do you mean by Same Origin Policy? How to handle it?
A: An Origin is a sequential combination of host, scheme, and port of the URL. The issue of the same-origin policy restricts accessing the DOM of a document from an origin that is different from the one that a user is trying to access the document.

The Selenium Core isn’t allowed to access the elements from an origin that is different from where it was launched. Selenium Remote Control was introduced in order to handle the problem of Same Origin Policy.

Q: Do you know how to get a text of a web element using Selenium?
A: In order to retrieve the inner text of a specified web element, Selenium offers the get command. It returns a string value and doesn’t require any parameters. Get command is one of the most widely used commands for verifying errors, labels, messages, etc. displayed on webpages. The general syntax for the get command is:

String Text = driver.findElement(By.id(“Text”)).getText();

Q: Please enumerate the various types of Drivers and Waits available in WebDriver.
A: WebDriver provides support for the following drivers:

  • AndroidDriver
  • ChromeDriver
  • FirefoxDriver
  • HtmlUnitDriver
  • InternetExplorerDriver
  • IPhoneDriver
  • OperaDriver
  • SafariDriver

There are two types of waits available in WebDriver, explained as follows:

  • Implicit Wait – Used for providing a default waiting time between each successive test step or command across the entire test script. Hence, the next test step or command will only execute when the set default waiting time, say 30 seconds, have passed since the execution completion of the previous test step or command. Can be applied to a particular instance or several instances.
  • Explicit Wait – Used for halting the execution until the occurrence of a particular condition or till the elapsing of the maximum time. Applied for a particular instance only.

Q: What do you understand by Object Repository? How do you create one in Selenium?
A: The term Object Repository refers to the collection of web elements that belong to AUT (Application Under Test) and their locator values. A corresponding locator value can be populated from the Object Repository whenever an element is required within the script.

Instead of hardcoding locators within the scripts, they are stored in a centralized location using Object Repository. Typically, the objects are stored in an excel sheet in Selenium which acts as the Object Repository.

Q: Please explain how to click on a hyperlink using its text.
A: The following command finds a specified element using the linkText() method and then clicks on that element to redirect the user to the corresponding webpage:


Another command that can be used for the same purpose is:


In this command, we use the partialLinkText() method. The aforementioned command finds the element based on the substring, Goo in this case, of the link provided.

Q: What is the most important difference between driver.close() and driver.quit() commands in Selenium?
A: The close() method closes the currently accessed window by the WebDriver. Neither does the command requires any parameter nor does it returns any value.

Unlike the close() method, the quit() method is used for closing down all the windows opened by the program. Like close() command, the quit() method doesn’t require any parameter nor does have any return value type.

Q: How will you find more than one web element in the list using Selenium?
A: Selenium offers WebElement List for finding more than a single web element in the list. Its use is demonstrated by the following code snippet:

List <WebElement> elementList =
Int listSize = elementList.size();
for (int i=0; i<listSize; i++)

Q: Can you explain the differences between Selenium and QTP?

  • Availability – Selenium is an open-source and free-to-use testing tool. QTP, on the other hand, is a licensed and commercial testing tool.
  • Browser Compatibility – While QTP provides support for only Chrome, Firefox, and Internet Explorer, Selenium can be used with the aforementioned plus Opera, Safari, and several others.
  • Object Repository – QTP automatically creates and maintains an Object Repository. However, this is not the case with Selenium as one 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 a multitude of programming languages, including C#, Java, Perl, Python, and Ruby.
  • Testing Support – Whereas Selenium offers testing of only web applications, QTP provides testing support for both web-based and Windows-based applications.
  • Vendor Support – No vendor support is available with Selenium while the same is available for QTP.

Q: How will you handle web-based pop-ups in Selenium?
A: 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() – Returns text displayed on the alert box
  • void accept() – Clicks on the ‘Ok’ button as soon as the pop-up appears
  • void dismiss() – Clicks on the ‘Cancel’ button as soon as the pop-up appears
  • void sendKeys(String stringToSend) – Inputs a specified string pattern in the alert box

Q: Can you explain the various types of navigation commands supported by Selenium?

A: Selenium supports a total of 4 navigation commands, listed as follows:

  • navigate().back() – Takes the user back to the previous webpage as per the web browser history. Requires no parameters
  • navigate().forward() – Navigates the user to the next webpage in the web browser history. Requires no parameters
  • navigate().refresh() – Reload all the web elements by refreshing the current webpage. Requires no parameters
  • navigate().to() – Lets the user launch a new web browser window and navigate to the specified URL given as a parameter

Q: When should we use findElement() and findElements()?
A: findElement() – Used for finding the first element in the current webpage matching to the specified locator value. Irrespective of the number of positive matches, only the first element will be fetched. Its general syntax is:

WebElement element = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

findElements() – Used for finding all elements matching the specified locator value in the current webpage. All matching elements will be fetched and stored in the list of WebElements. The general syntax for the method is:

List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

Q: What is JUnit? Explain the various JUnit annotations.
A: JUnit is a Java-based testing framework from Apache that complements Selenium. Various JUnit Annotations are enumerated as follows:

  • @After – Lets the system know that this method will be executed every time a test method achieves completion
  • @AfterClass – Lets the system know that this method must be executed once after any of the test methods
  • @Before – Lets the system know that this method will be executed just before every time a test method starts execution
  • @BeforeClass – Lets the system know that this method must be executed once before any of the test methods start execution
  • @Ignore – Lest the system know that this method shall be ignored i.e. it shall not be executed
  • @Test – Lets the system know that this method is a test method. It is possible to have several test methods in a single test script

Q: Please explain the various types of Test Automation Frameworks.

  • Behavior-Driven Development Framework – Allows automating functional validations in an easy-to-read and understandable format for different professionals, including analysts, developers, and testers.
  • Data-Driven Testing Framework – Helps in segregating the test script logic and the test data. Allows storing test data in some external database in the form of key-value pairs. These keys are used for accessing as well as populating the data within the test scripts.
  • Keyword-Driven Testing Framework – It is an extension to the data-driven testing framework in a way that in addition to separating test data from the test scripts, a keyword-driven testing framework stores a part of the test script code in an external data file.
  • Library Architecture Testing Framework – Works on the principle of determining the right steps and then grouping them together into functions under a library. These functions are called in the test scripts whenever required.
  • Module-Based Testing Framework – Divides each application under testing into a number of logical and isolated modules. A distinct test script is created for each module.
  • Hybrid Testing Framework – Offers features belonging to different types of testing frameworks. The idea is to reap in all the benefits of various approaches with a single testing tool.

Well, that sums up the list of the 20 most important Selenium interview questions. Going through the list will surely help you tighten up your preparation for that upcoming Selenium interview. All the best!

People Might be Interested In:

Please leave your comments in the comments window below and don’t forget to check out some of the best Selenium tutorials to step up your web-based application testing game.

Related Posts

Your email address will not be published. Required fields are marked *