Akhil Bhadwal | 28 Jul, 2023

Top 40 Selenium Interview Questions and Answers in 2024

 

Written entirely 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.

Every aspiring tester, especially one aiming to work with web-based applications, must have some knowledge about Selenium. Today, web-based testing positions will almost certainly feature Selenium interview questions.

We’ve compiled some of the most common Selenium interview questions and answers. They’ve been divided into basic and advanced questions for your convenience. We start off with some basic selenium testing interview questions. Let’s get right into it.

Click here to download Hackr.io’s Selenium Interview Questions PDF.

Basic Selenium Interview Questions 

1. What is Selenium? State its components.

Selenium is a suite of tools that are used explicitly for automated web testing purposes. Its components are the Selenium IDE (Integrated Development Environment), WebDriver and RC, and Grid.

Selenium Components

2. How are Selenium 2.0 and Selenium 3.0 different?

Selenium 2.0 has consolidated Selenium RC and WebDriver to make a single tool, while Selenium 3.0 is the latest version, which has Beta 1 and Beta 2 updates.

3. What are the various test types Selenium supports?

The test types supported by Selenium are:

  1. Functional
  2. Regression
  3. CruiseCont
  4. Hudson
  5. Jenkins
  6. Quick Build

4. What are 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 segregate the test script logic and the test data. It also 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.

5. What is the role of assertion and what are the various types?

The role of assertion is to act as a verification point. It helps verify the state of the application, ensuring that it conforms to expectations. There are three types:

  1. Assert
  2. Verify
  3. WaitFor

6. Explain Selenium’s components in detail.

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: Communicates directly with the web browser in addition to using its native compatibility to automate.

7. What are the limitations of Selenium?

  • Only supports web-based applications
  • Bitmap comparison is not supported
  • Third-party tools are required for reporting purposes
  • Vendor support is minimal compared to other commercial tools like HP UFT
  • Challenging to maintain objects in Selenium
  • Does not offer testing for barcode and captcha readers

8. What are the different types of locators in Selenium?

A locator is a kind of address that offers a unique way of identifying a web element on 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

9. What is the difference between assert and verify in Selenium?

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 in 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.

The 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.

10. What are the parameters in Selenium?

There are four parameters in Selenium which includes:

  1. Host
  2. URL
  3. Port Number
  4. Browser

11. What is the Same Origin Policy and how do you handle it?

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.

12. What are the various types of Drivers and Waits available in WebDriver?

WebDriver provides support for the following drivers:

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

There are two types of waits available in WebDriver:

  • 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. It 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.

13. What is an Object Repository? How do you create one?

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 the Object Repository. Typically, the objects are stored in an excel sheet in Selenium which acts as the Object Repository.

Selenium IDE (Udemy Course)

14. What are the differences between Selenium and QTP?

Selenium

QTP

Open-source

Commercial

Used for testing web-based applications

Used for web-based applications and testing client-server applications

Supports Safari, Opera, and Firefox on Linux, Mac, and Windows

Supports only the Internet Explorer on Windows

Supports Python, Java, Perl, and Ruby

Only supports VB Script

Requires manual creation of an Object Repository while working with the automation testing tool

QTP automatically creates and maintains an Object Repository

No vendor support

Has vendor support

Advanced Selenium Interview Questions 

The following command finds a specified element using the linkText() method and then clicks that element to redirect the user to the corresponding webpage:

driver.findElement(By.linkText(“Google”)).click(); 

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

driver.findElement(By.partialLinkText(“Goo”)).click();

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

16. What is the most important difference between the driver.close() and driver.quit() commands?

The close() method closes the currently accessed window by the WebDriver. The command neither requires a parameter nor does it return any value.

Unlike the close() method, the quit() method is used for closing down all the windows opened by the program. Like the close() command, the quit() method doesn’t require parameters or have any return values.

17. How do you find more than one web element in the list?

Selenium offers a WebElement List for finding more than a single web element in the list. The following code snippet demonstrates it:

List elementList =

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

Int listSize = elementList.size();

for (int i=0; i<listSize; i++)

{

serviceProviderLinks.get(i).click();

driver.navigate().back();

}

18. How do you know if an element is displayed on the screen?

The WebDriver component of the Selenium suite allows you to check the visibility of web elements, which can be buttons, checkboxes, drop boxes, labels, radio buttons, and so on. The following three methods let you do this:

  • 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();​

19. How do you get the text of a web element?

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. The 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();

20. What is XPath in Selenium?

XPath is a type of locator in Selenium that is used to locate a web element based on its XML path. XML stands for 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 on a webpage. The underlying principle of XPath is traversing between several elements across the entire webpage and allowing them to find an element with the reference of some other element.

21. How do you launch the browser using WebDriver?

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();

22. How do 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();

alert.accept();

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

23. What are the various types of navigation commands?

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 web page 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.

24. When is findElement() and findElements()?

The function findElement() is 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”));

The function findElements() is 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 elementList = driver.findElements(By.xpath(“//div[@id=’some id’]//ul//li”));

25. What is JUnit? What are the various JUnit annotations?

JUnit is a Java-based testing framework from Apache that complements Selenium. The JUnit annotations are 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.

26. Differentiate between the Type Keys and Type Commands.

Types Keys collect different value attributes using JavaScript while the Type Commands is actual user input.

27. What is the role of set Speed() and Sleep() methods?

The role of set Speed() and Sleep() is to delay the speed of execution.

28. Define heightened privileges browsers.

Heightened privileges browsers act as proxy injections that allow different websites to do things that are normally not permitted. These browsers allow Selenium core to penetrate the AUT directly and thereby read and write its content without passing the whole AUT through the Selenium RC server.

29. What are the major differences between the Selenium Test Tool and the Borland Silk Test Tool?

The major differences between the Selenium Test Tool and the Borland Silk Test Tool are:

Selenium Test Tool

Borland Silk Test Tool

Free

Commercial

Automated

Manual

Supports Internet Explorer, Firefox, Safari, Opera, and various others

Supports Internet Explorer and Firefox

Supports testing in several languages

Supports testing in script language

Supports only web applications

Supports only client-server applications

30. How is Webdriver beneficial over Selenium Server?

Webdriver does not require the Selenium Server because it uses a completely different technology. It provides Selenium RC functionality, which provides backward compatibility to Selenium 1.0.

It also makes a direct call to various browsers for automation. At the same time, in the case of Selenium RC, it requires the Selenium Server to input the Javascript into the browser.

31. What are some features of Selenium WebDriver from Selenium 1.0?

Some features of Selenium WebDriver from Selenium 1.0 are:

  • Handles multiple frames, browsers, windows, alerts, and pop-ups
  • In-page navigation
  • Offers drag and drop facility on the page
  • Applies the Ajax-based User Interface (UI) elements
  • Offers multiple browser testing facilities which helps in improving functionality of browsers

32. Can we handle colors in WebDriver?

Yes, we can handle colors in WebDriver using the getCssValue(arg0) function. It helps get the color by sending the 'color' string as an argument.

33. Can we store a value, which is a text box?

Yes, we can store a value, which is a text box using WebDriver.

The code is

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

34. What are the three arguments that can be taken into consideration for Switching?

The three arguments that can be taken into consideration for switching includes:

  1. A number: This will select the number by its zero-based index
  2. A name or ID: This will select a frame by its name or ID
  3. Previously found WebElement: This will help in using the previously located WebElement to select a frame

35. What are the exceptions to Selenium WebDriver?

Selenium WebDriver

There are many WebDriver Exceptions in Selenium. However, the most common ones are:

  1. NoSuchElementException
  2. ElementNotVisibleException
  3. SessionNotFoundException
  4. NoSuchFrameException
  5. NoAlertPresentException
  6. NoSuchWindowException
  7. StaleElementReferenceException

36. Which is the best WebDriver implementation?

The best WebDriver implementation of the HTML unit is the fastest because it does not execute the tests on the browsers but applies plain HTTP requests, which is quick and helps launch the browser and execute the tests.

37. Write a code snippet to launch Chrome browser in WebDriver.

WebDriver driver = new ChromeDriver();

WebDriverWait wait = new WebDriverWait(driver, 30);

String url = "https://www.google.com";

driver.get(url);

wait.until(ExpectedConditions.titleContains("Google"));

System.out.println("Page title is: " + driver.getTitle());

driver.quit();

38. What’s the Difference Between ‘/’ and ‘//’ in XPath?

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.

39. How Do You Handle Authentication Pop-ups?

To handle authentication pop-ups, verify its appearance and then handle them using an explicit wait command.

Start with the explicit wait command:

WebDriverWait wait = new WebDriverWait(driver, 10);

Use the Alert class for verification:

Alert alert = wait.until(ExpectedConditions.alertIsPresent());

Once verified, provide the credentials:

alert.authenticateUsing(new UserAndPassword(<username>, <password>));

40. What is the SwitchTo() Command?

The switchTo() command switches between windows, frames or pop-ups within the application. Every window has a unique alphanumeric value called “Window Handle”, given by the WebDriver.

Use the particular window’s window handle you want to switch to:

String handle= driver.getWindowHandle();

Switch to the window:

driver.switchTo().window(handle);

You can also do this:

for(String handle= driver.getWindowHandles())

{ 
driver.switchTo().window(handle); 
}

Start Preparing with These Selenium Interview Questions

That sums up the list of the top Selenium interview questions and answers. This should help you prepare for that upcoming Selenium interview. Remember to also put all of these concepts into practice.

If you’re looking for more Selenium learning material, the QA preparation for Selenium Automation and Agile Interviewis a helpful course. You can also check some of the best Selenium tutorials we have to further help you ace those Selenium interview questions.

Bonus Tips

Besides preparing with the Selenium interview questions, there are a few other things you must focus on. 

Most importantly, make sure you understand Java and can implement it properly. You should also pay special attention to API testing. 

You should also find practice exercises online, as well as more Java programming-focused questions by searching for Selenium Java interview questions.

Frequently Asked Questions

1. Is Selenium a tool or API?

Selenium is an open source project that offers a range of testing tools and frameworks for automation testing. You can learn more about the details of the tools in the Selenium testing interview questions we have listed above.

2. Which tool is used for Selenium?

Selenium provides a number of tools. These include Selenium IDE, Selenium WebDriver and Selenium Grid. The Selenium automation interview questions we have provided explains these tools in detail.

People are also reading:

 

By Akhil Bhadwal

A Computer Science graduate interested in mixing up imagination and knowledge into enticing words. Been in the big bad world of content writing since 2014. In his free time, Akhil likes to play cards, do guitar jam, and write weird fiction.

View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

I accept the Terms and Conditions.
Thanks for subscribing! Look out for our welcome email to verify your email and get our free newsletters.

Disclosure: Hackr.io is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

In this article

Learn More

Please login to leave comments