Selenium Interview Questions

Last updated on Jan 08, 2024

Selenium is an automated testing framework which is designed to automate the test cases for validating the web applications across different browsers and platforms. The tool implements programming languages such as Java, Python, C#, etc for creating the test scripts. The Selenium is a software suite with a list of tools designed to meet the requirement needs of an organization. The list includes.

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

In this article, you can go through the set of selenium interview questions most frequently asked in the interview panel. This will help you crack the interview as the topmost industry experts curate these at HKR training.

Let us have a quick review of the selenium interview questions.

Most Frequently Asked Selenium Interview Questions and Answers

Why should Selenium be selected as a testing tool?

The reasons are.

  • Selenium is an open-source tool.
  • It has a large user base and helping communities.
  • It can work with the cross browsing capabilities on Firewall, Chrome, Internet Explorer, Safari etc.
  • It has great platform compatibility which runs on the operating systems such as Windows, Mac OS, Linux etc.
  • Support for multiple programming languages such as Java, C#, Ruby, Python, Pearl etc.
  • It has fresh and regular repository developments.
  • It supports distributed testing.

Become a master of Selenium by going through this HKR Selenium Training!

What are the testing types supporting by Selenium?

Selenium support two types of testing.

  1. Functional testing.
  2. Regression testing

What are the limitations of Selenium?

 The limitations are.

  • It supports the testing only for web-based applications.
  • The mobile applications cannot be tested by Selenium.
  • Captcha and Barcode readers also can’t be tested by Selenium.
  • The reports can be generated only with third-party tools like TestNG or JUnit.
  • The user should possess knowledge of programming languages.

What is the difference between assert and verify commands?

Assert:

The Assert command checks for the condition if true or false. If you assert for an element and want to check if is present in a page or not then the program control will execute the next test if the condition is true else the execution stops and no further test will be executed when the condition becomes false.

Verify:

Verify command also checks for true or false but irrespective of the condition the program execution will not halt. This means any failure during verification won’t stop executing the further test steps.

How do I launch the browser using WebDriver?

The following syntax is used in launching the Browser.

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

Explain the difference between single and double slash in X-path?

Single slash ‘/ ’:

  • The single slash ( / ) will start the selection from the document node.
  • It allows users to create “absolute” path expressions.

Double Slash ‘// ’:

  • The Double slash ( // ) will start the selection matching anywhere in the document.
  • It enables users to create “relative” path expressions

What are the different types of waits available in WebDriver?

 WebDriver has two types of waits.

  1. Implicit: These are used to provide default waiting time say 30 seconds for consecutive test commands across the entire test script. This subsequent step would execute when 30 seconds have elapsed after executing the previous step/command.
  2. Explicit: These are used to halt the execution when it reaches its maximum time for elapsing or when a particular condition is met. These waits are applied only for a particular instance.

How can you find if an element is displayed on the screen?

To the visibility of web elements, the WebDriver facilitates the user with the following web elements that can be buttons, drop boxes, checkboxes, radio buttons, labels etc. The methods are.

  1. isDisplayed()
  2. isSelected()
  3. isEnables()

Syntax:

isDisplayed():

boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isSelected():

boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();
isEnabled():

boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

How to select value in a dropdown?

The values are selected using WebDriver’s select class.

Syntax:

1. selectByValue:

Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));

selectByValue.selectByValue(“greenvalue”)

 2. selectByVisibleText:

Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));

selectByVisibleText.selectByVisibleText(“Lime”);

3. selectByIndex:

Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));

selectByIndex.selectByIndex(2);

. What is the difference between single and double slash in X-path?

Single slash ‘/’

  • It starts selection from the document node.
  • Single slash allows you to create ‘absolute’ path expressions.

Double slash ‘//’

  • It starts selection matching anywhere in the document.
  • Double slash enables to create ‘relative’ path expressions.

. List out the technical challenges with Selenium?

The challenges faced by Selenium are.

  • Having support only for web-based applications.
  • Unsupported for Bitmap comparison.
  • The reporting capabilities depend on third-party tools.
  • No vendor supported for commercial tools like HP UFT.
  • There exists no object repository concept in Selenium and maintenance is difficult.

. Why testers should opt for Selenium and not for QTP?

  • QTP is a commercial tool while Selenium is open-source.
  • Selenium is tested only on web applications while QTP can test client-server applications also.
  • Selenium is supported by web browsers such as Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc but QTP is only limited to Internet Explorer on Windows.
  • Selenium is supported by programming languages such as Ruby, Pearl, Python while QTP supports only VB script.

. How do you handle web-based pop-up?

 The pop-ups are handled using the Alert interface of WebDriver. These four methods used along with Alert interface. 

void dismiss() - This method clicks the “Cancel” button when the pop-up window appears.

void accept() - This method clicks the “Ok” button when the pop-up window appears.

String getText() - This method returns the text which is displayed on the alert box.

void sendKeys(String stringToSend) - The sendKeys() enters the specified string pattern into alert box.

Syntax:

// accepting javascript alert

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

alert.accept();

. What are the four parameters that must be passed in Selenium?

The parameters are.

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

. What is the difference between setSpeed() and sleep() method?

 Both methods delay the execution speed.

thread.sleep():It stops the current java thread for a specific time period. It can be done only once.

  • It takes the single argument in an integer format.

Example: thread.sleep(2000)- It will wait for 2 seconds.

  • It will wait only for once at the command given at sleep.

setSpeed():It stops the execution for a specific time period for every selenium command.

  • It takes the single argument in an integer format.

Example: selenium.setSpeed(“2000”)- It will wait for 2 seconds.

  • It runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed.

The setSpeed() is useful in demonstrating or while using a slow web application.

. How can you retrieve the CSS properties of an element?

 The CSS property values are retrieved using the get() method.

Syntax:

driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

driver.findElement(By.id(“id“)).getCssValue(“font-size”);

Selenium Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

 

. What is the difference between “findElement()” and “findElements()”?

findElement():

  • It finds the first element within the current page by using “locating mechanism”.
  • The method returns a single WebElement.

findElements():

  • By using the “locating mechanism” this method finds all elements within a current page.
  • The method returns a list of web elements.

. How to mouse hover on a web element using a web driver?

WebDriver offers a wide range of interaction utilities for users who can also exploit the events of mouse automation and keyboard. Action interface is one utility which simulates the single user interactions.

In this scenario, we use the Action interface to mouse hover on a drop to open a list of options.

Sample Code:

// Instantiating Action Interface

Actions actions=new Actions(driver);

// howering on the dropdown

actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();

// Clicking on one of the items in the list options

WebElement subLinkOption=driver.findElement(By.id("id of the sub link id"));

subLinkOption.click();

. Explain the Data-driven and Keyword-driven frameworks.

Data-driven framework: 

In this framework, the test data will be separated and are kept outside the Test Scripts while the logic of Test Case resides inside the Test Scripts. The Test data will be read from external excel files and are loaded into the variables of Test Script. Variables are used for both input and verifications values.

Keyword-driven framework: 

This framework requires the development of data tables and keywords that are independent of test automation. In this test, the functionality of an application in the test will be documented in a table as well as step by step instructions for each test.

. Explain about the JUnits annotation linked with Selenium.

The JUnits annotation linked with Selenium are.

  • @Before public void method() -It performs the method() before each test and can prepare the test.
  • @Test public void method() - Annotations @Test identifies that this method is a test method environment.
  • @After public void method() - This annotation is used before executing a method. The test method must start with test@Before.

. Mention the five different exceptions you had in Selenium WebDriver.

 The five exceptions in Selenium are.

  • WebDriverException
  • NoAlertPresentException
  • NoSuchWindowException
  • NoSuchElementException
  • TimeoutException

. Explain how can you switch between frames.

 For switching between the frames, the web drivers “driver.switchTo().frame()” takes one of the three possible arguments.

  • A number:  It selects the number by its index which is zero-based.
  • A name or ID: Select a frame by its name or ID.
  • Previously found WebElement: Selecting a frame by using its previously located WebElement.

. What is the difference between “getWindowHandles()” and “getWindowHandle()”?

getWindowHandles(): The method is used to get the address of all open browser. The return type of this method is Set.

getWindowHandle(): The method is used to get the address of the current browser and the return type of this method is a string.

. What is the difference between POI and jxl jar?

JXL jar:

  • JXL supports binary-based formats such as “.xls”. It doesn’t support Excel 2007 of “.xlsx” format which is based on XML.
  • The last updated year of JXL API is 2009.
  • The JXL documentation is not that comprehensive as compared to POI.
  • The rich text formatting is not supported by JXL API.
  • JXL API performs faster than the POI API.

POI jar:

  • POI supports all the formats.
  • POI is updated and released regularly.
  • The POI documentation is well prepared and highly comprehensive.
  • The rich text formatting is supported by POI API.
  • POI API performance is slow as compared to JXL API.

. What is an object repository? How do you create an object repository in Selenium?

Object repository is a term that is used while referring to the collection of web elements which belongs to an Application Under Test (AUT) and its locator values. When an element is required in the script, the locator value is populated from the object repository.  Object repository is used for storing the locators in a centralized location instead of hardcoding them within the scripts.

In Selenium, the objects are stored in an excel sheet which can be populated inside the script whenever it is required.

. List out different types of locators?

 The different types of locators are.

  • By.id()
  • By.name()
  • By.tagName()
  • By.className()
  • By.linkText()
  • By.partialLinkText()
  • By.xpath
  • By.cssSelector()

Become a master of Selenium by going through this HKR Selenium Tutorials !

Subscribe to our YouTube channel to get new updates..!

.What are the features of TestNG and list some of the functionality in TestNG which make it more effective?

TestNG is a testing framework that is based on JUnit and NUnit which simplifies a broad range of testing needs from unit testing to integration testing. The effective testing framework functionalities are.

  • Providing support for annotations.
  • Providing support for data-driven testing.
  • Flexibility in the test configuration.
  • The ability of re-executing the failed test-cases.

. What are the advantages of Selenium?

The advantages are.

  • Support for multiple programming languages such as C#, PHP, Java, Perl, Python.
  • Support for different operating systems like Windows, Linux and Mac OS.
  • Implements the powerful methods for locating the Xpath, DOM, CSS elements.
  • Selenium has a large developer community supported by Google.

. How do you set test case priority in TestNG?

 The following code explains how to set priority in TestNG.

Code Snippet:

package TestNG;

import org.testng.annotations.*;

public class SettingPriority {

@Test(priority=0)

public void method1() {

}

@Test(priority=1)

public void method2() {

}

@Test(priority=2)

public void method3() {

}

}

Test Execution Sequence:

  1. Method1
  2. Method2
  3. Method3

. What are the capabilities of Selenium WebDriver or Selenium 2.0?

WebDriver is used when improvement support is required. The capabilities are of WebDriver includes.

  • Ability to handle multiple frames, pop-ups, multiple browser windows and alerts.
  • Page navigation support and drag & drop interactions.
  • UI elements based on Ajax.
  • Multi-browser testing including improved functionality for the browser which is not well supported by Selenium 1.0

. Mention the various automation tools that could integrate with Selenium to accomplish Continuous Testing?

Ans. The following are the various automation tools that can use to integrate with Selenium to accomplish Continuous Testing:-

  • Docker
  • Jenkins
  • Maven
  • Azure DevOps
  • CircleCI
  • TravisCI
  • Bamboo

. Define Assertion in Selenium?

Ans. An assertion in Selenium is a testing or verification method used to check whether a given condition is true or false. The assertions are useful to verify the state of applications or elements on a page, whether they are present or not. Also, assertions are very important in testing with Selenium as they allow us to verify whether the application's state meets the required expectations.

. What is meant by XPath?

Ans. XPath refers to XML Path, a language useful to query XML documents and is an approach that helps to detect elements within Selenium. It also includes a path expression having some conditions. Moreover, XPath is also useful for detecting the nodes within XML documents.

. Define XPath Attributes and XPath Absolute?

Ans. XPath Attributes are an essential part of Selenium XPath that is added to the element which contains the most valuable and essential information. These are suggested when no suitable ID is available for the element we want to find out. 

XPath Absolute expressions begin with a ("/") single forward slash that defines the document's root element. The simplest type of Selenium XPath allows users to state the full XPath location starting from the root HTML tag to the elements mentioned.

. Distinguish between the commands driver.quit() and driver.close()

Ans. The following are the primary differences between the driver. quit() and the driver.close() commands.

The driver. quit() command is useful for quitting the driver and closing all the open browser windows. 

The driver. close() command is useful to close only the current browser window in focus.

. What is meant by POM, and describe its uses?

Ans. POM refers to the Page Object Model, a design pattern for building an Object Repository for the web UI (user interface) elements. It helps to improve the readability of the code along with its reusability. Also, we can run many test cases on the object directory. It is because the object directory is free from the selenium test cases.

. State the key differences between the Type Command and Typekeys in Selenium?

Ans. The command TypeKeys() activates the JavaScript event in many cases where the command type() doesn't. The value attribute is populated by TypeKey() through JavaScript. But the Type() command copies the typing of the actual user.

. Distinguish between the commands

Ans. The command "type" is useful for entering the text or values into the text box of the web application. The command "typeAndWait" is also useful for entering the text or value into the web page. But it waits some time to load the page before moving to another command. 

The "type" command doesn't wait for the page to load, whereas the "typeAndWait" command waits for the same. If you're not sure about the text, you enter and whether it will or not cause the page to refresh, it is better to use the "typeAndWait" command.

. Define the advantages of Automation Testing?

Ans. Automation testing will be highly beneficial to speed up the software testing process. Automation testing saves much time and the resources we spend on manual testing. Moreover, it improves the accuracy of the test cases. It also provides detailed testing reports that help to know the areas of specific attention.

. List out the different WebDrivers that support the Mobile Testing Drivers?

Ans. The following are the various WebDrivers support Mobile testing drivers:-

  • IPhoneDriver
  • AndroidDriver
  • RemoteWebDriver
  • Selendroid

. What is meant by Selenese?

Ans. Selenese is a set of commands in Selenium useful for web application testing. Moreover, Selenese is a scripting language that helps to write Selenium IDE test scripts. Using the commands of Selenese, a tester can check the broken links, alerts, etc. There are three different Selenese commands Actions, Accessors, and Assertions.

. Mention the element locator in Selenium IDE that helps find the web page elements?

Ans. The following are the different types of element locators in Selenium IDE for finding the web page elements: Html ID, CSS Locators, Html Name, and Xpath locators.

. List out the various WebDriver APIs that Selenium contains?

Ans. Selenium has the following WebDriver APIs:-

  • ChromeDriver
  • FirefoxDriver
  • AdnroidDriver
  • iPhone driver
  • HtmlUnitDriver
  • driver (Internet Explorer)
  • RemoteWebDriver, etc.

. What is the format in which the source view displays your script within Selenium IDE?

Ans. It displays them in XML format.

. Name the different types of tests that Selenium supports.

Ans. Selenium supports the below test types:-

  • Regression Testing
  • Sanity Testing
  • Functional Testing
  • Cross Browser Testing
  • UI Testing
  • Integration Testing
  • Smoke Testing

Selenium Certification Training

Weekday / Weekend Batches

. Define the way to invoke or call an application within Selenium WebDriver?

Ans. When we use Selenium WebDriver, we can start applications either using a get() method or a navigate() method. Also, we can use Selenium IDE (a third-party tool) to invoke the applications. But to perform this, you must have the application's URL in advance.

. What is the command used to obtain the text of a Web Element?

Ans. To obtain the text of a specific web element "get" command is used. The command doesn't need any special parameter, and it gives back a string type value. Moreover, this command verifies the web page's messages, errors, etc.

. Which web driver executes much faster?

Ans. The HTMLUnit Driver executes much faster in Selenium.

. Define StartPoints and BreakPoints in Selenium.

Ans. A Startpoint is where the execution starts and is useful while running the test script from the center of the code. A breakpoint is useful to terminate or stop the code execution and to check whether the code is working properly as per expectation.

Related Article : What Is XPath In Selenium

. List out the various navigation commands in Selenium?

Ans. The following are the navigation commands used in Selenium:-

  • navigate().foward()
  • navigate().back()
  • navigate().to()
  • navigate().refresh()

. Explain the ways to customize the TestNG report in Selenium?

Ans. Below are the two different ways to tailor the TestNG reports in Selenium.

  • We can use ITestListener Interface
  • We can use IReporter Interface

About Author

As a senior technical content writer for HRK tainings, srivalli patchava has a greater understanding of today's data-driven environment, which includes key aspects of data management and IT organizations. She manages the task of creating great content in the areas of software testing, DevOps, Robotic process automation. Connects with her on Linkedin and Twitter.

Upcoming Selenium Certification Training Online classes

Batch starts on 23rd Mar 2024
Mon - Fri (18 Days) Weekend Timings - 10:30 AM IST
Batch starts on 27th Mar 2024
Mon & Tue (5 Days) Weekday Timings - 08:30 AM IST
Batch starts on 31st Mar 2024
Mon - Fri (18 Days) Weekend Timings - 10:30 AM IST
To Top