Are you looking to get a discount on popular programming courses? Then click here. View offers

Interview Questions and Selenium


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



Selenium Interview Questions

Posted in Interview Questions, Selenium

Table of Contents

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 be knowledgeable about Selenium. These days, 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.

Selenium Interview Questions - Basic

We start off with some basic selenium testing interview questions. Let’s get right into it.

1. What is Selenium? State its components.

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

What is Selenium State its 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 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.

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 in verifying 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: Communicated 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.

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.

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

Supports only 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

 

Selenium Interview Questions - Advanced

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, Goo in this case, 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? What’s the difference between “/” and “//”?

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.

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.

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 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 a 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?

There are five different exceptions to Selenium WebDriver, which are:

  1. TimeoutException
  2. WebDriverException
  3. NoAlertPresentException
  4. NoSuchElementException
  5. NoSuchWindowException

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.

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.

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

People are also reading:

Akhil Bhadwal

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 posts by the Author

Leave a comment

Your email will not be published
Cancel
jarek
jarek

I found a bug (without using Selenium:). Correct this one:
"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."

It's not about verify command, but assert. On assert if it failed, the test will stop.

TODAY'S OFFERS
close

Select from the best sales here

VIEW ALL DISCOUNTS