Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What are the Selenium suite components?

Answer»

Selenium is a package of several testing tools and is therefore often referred to as a Selenium Suite with each of these tools designed to cater to a different testing requirement.

Following are the different components of Selenium Suite:



  • Selenium Integrated Development Environment (IDE): It is a Firefox/Chrome plug-in that is developed to speed up the creation of automation scripts by recording the user actions on the web browser and exporting them as a reusable script.


  • Selenium Remote Control (RC): It is a server that enables users to generate test scripts in their preferred programming language. It accepts commands from the test scripts and sends them to the browser as Selenium core JavaScript commands, for the browser to behave accordingly.


  • Selenium WebDriver: It is a programming interface that helps create and run test cases by directly communicating with the web browser and using its native compatibility to automate. Unlike RC, it doesn’t require an additional server to create and run test cases.


  • Selenium Grid: It allows parallel execution of tests on different browsers and operating systems by distributing commands to different machines simultaneously.


2.

In Selenium, how will you wait until a web page has been loaded completely?

Answer»

There are two methods of making sure that the web page has been loaded completely in Selenium. 

They are as follows :

1. Immediately after creating the webdriver instance, set an implicit WAIT

temp = driver.Manage().TIMEOUTS().ImplicitWait;

On every page navigation or RELOAD, this will try to wait until the page is fully loaded.

2. Call JavaScript RETURN document.readyState till "complete" is returned after page navigation. As a JavaScript executor, the web driver instance can be USED

Code example:

new WebDriverWait(firefoxDriver, pageLoadTimeout).until( webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
3.

Differentiate between findElement() and findElements() in the context of Selenium with proper examples.

Answer»

Following table lists the differences between findElement() and findElements() in SELENIUM :

findElement()findElements()
The first web element that matches the locator is returned.It GIVES you a list of all the web items that match the locator.
If there are no matching web elements, a NoSuchElementException is produced.If there are no matching elements, an empty list is returned.
Syntax − WebElement button = webdriver.findElement(By.name("<<Name value>>"));Syntax − List<WebElement> buttons = webdriver.findElements(By.name("<<Name value>>"));
  • Using findElements():-
// JAVAimport org.openqa.selenium.By;import org.openqa.selenium.Keys;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import java.util.concurrent.TimeUnit;public class findElements { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaibhav\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.exampleurl.com/example.htm"; driver.get(url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); List<WebElement> rows = driver.findElements(By.xpath("//table/tbody/tr[2]/td")); // xpath with INDEX appended to get the values from the row 1of table using findElements(), which returns a list System.out.println("The number of values in row 2 is "+ rows.size()); driver.close(); }}

Explanation - In the above code, first of all, we import all the necessary headers and then set up the driver for the chrome browser. We use the findElements() method to find all the values present in the 2nd row of a table in the given URL web page using the XPath of the element.

  • Using findElement() :-
import org.openqa.selenium.By;import org.openqa.selenium.Keys;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import java.util.concurrent.TimeUnit;public class findTagname { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\Users\\vaibhav\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.exampleurl.com/example.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); driver.findElement(By.cssSelector("input[ID='search']")).sendKeys("Selenium"); //Using id tagname attribute combination for css expression and get the element from findElement() driver.close(); }}

Explanation - In the above code, first of all, we import all the necessary headers and then set up the driver for the chrome browser. We use the findElement() method to find an input element having an id attribute set as search.

4.

What is the difference between the commands "type" and "typeAndWait" in the context of Selenium?

Answer»

The "type" command is used to enter keyboard key values into a software web application's TEXT box. It can also be used to CHOOSE values from a COMBO box, WHEREAS the "typeAndWait" command is used when you FINISH typing and the software web page begins to reload. This command will wait for the page of the software program to reload before proceeding. You must use a basic "type" command if there is no page reload event when typing.

5.

In Xpath, what is the difference between "/" and "//"?

Answer»

Single Slash "/" - A single slash is used to CREATE an XPATH with an absolute PATH, i.e. the XPath will begin with the document node/start node.

For example, 

Absolute XPath: /html/body/div/div/form/input

Here, /html is the root html node.

Double Slash "//" - The double slash is used to CONSTRUCT an Xpath with a relative path, which means the XPath can start selection from anywhere on the page.

For example,

Relative XPath: //input[@id = 'email']

Here, we can LOCATE an input having id = ‘email’ present anywhere in the document object model (DOM).

6.

What is meant by XPath in Selenium. Explain XPath Absolute and XPath Relative.

Answer»

XPath, also defined as XML-Path (Extensible MARKUP Language Path), is a language used to QUERY XML documents and provide functionalities like locating elements in Selenium by ITERATING through each ELEMENT in a webpage. In XPath, DATA is stored in a key-value pair format similar to an HTML tag. It uses a single slash, i.e. ‘ / ’ for creating an absolute path, and a double slash, i.e. ‘ // ’ for creating a relative path for an element to be located on a webpage.

7.

What is meant by an exception test in Selenium?

Answer»

An EXCEPTION test is a test that expects an exception to be thrown INSIDE a test CLASS. It expects a @Test annotation followed by the expected exception name in the brackets.

Eg: @Test(EXPECTEDEXCEPTION = NoSuchElementException.class) is an exception test for missing elements in Selenium.

8.

State the major difference between “assert” and “verify” commands in Selenium.

Answer»

Both “ASSERT” and “VERIFY” commands check whether the given CONDITION is true or false and the only difference between them is that:

  • Assert: Assert condition stops the execution of the testing if the given condition is false else would CONTINUE with the further tests.
  • Verify: Verify the condition doesn’t STOP the flow of execution irrespective of the condition being true or false.
9.

What is meant by a locator and name a few different types of locators present in Selenium.

Answer»

A locator is an address for UNIQUELY identifying web elements within a web page. There are DIFFERENT types of locators present in Selenium to IDENTIFY web elements uniquely and accurately like:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • Xpath
  • CSS Selector
  • DOM.
10.

What is meant by Selenese? Explain different types of Selenium commands.

Answer»

The LANGUAGE used for writing test scripts in Selenium IDE is called Selenese. It is a set of commands used to test your web application or system. Selenium commands could be DIVIDED into 3 major categories:

  • Actions: These are the commands INTERACTING DIRECTLY with web applications.
  • Accessors: These are the commands which allow users to store values to a user-defined variable.
  • Assertions: They enable a comparison of the current state of the application with its expected state.
11.

Can selenium be used to launch web browsers?

Answer»

Yes, Selenium provides good support to launch web BROWSERS like Google Chrome, Mozilla Firefox, Internet Explorer, etc.

The FOLLOWING COMMANDS can be used to launch web browsers using Selenium:

  • WEBDRIVER driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();
12.

Why should Selenium be selected as a testing tool for web applications or systems?

Answer»

SELENIUM provides the following advantages, which make it an excellent automated testing framework:

  • It is free and open-source software with a large user base and supports providing community.
  • It has cross-browser compatibility and supports multiple browsers like Google Chrome, Mozilla FIREFOX, Internet Explorer, EDGE, Opera, Safari, etc.
  • It supports multiple operating systems such as Windows, Linux, macOS, etc.
  • It facilitates the usage of multiple programming languages including SCALA, Ruby, Python, PHP, Perl, Java, Groovy, C#, etc.
  • It provides support for distributed testing as well.
13.

What are the disadvantages of using Selenium as a testing tool?

Answer»

The following are the disadvantages of USING Selenium as a testing TOOL:

  • Tests web applications only: Selenium supports the testing of only web-based applications. Mobile applications, Captcha, and Barcode readers cannot be tested using Selenium unless integrated with third-party tools like Appium and TestNG.
  • No built-in reporting and test management facility: Selenium can generate reports only using third-party tools like TestNG or JUnit.
  • Unavailability of reliable tech support: Since Selenium is an open-source tool, no dedicated support for USER issues is available.
  • May require the KNOWLEDGE of programming languages: Some prior programming knowledge is required to USE Selenium.
14.

What are the advantages of using Selenium as an automation tool?

Answer»

Following are the ADVANTAGES of using Selenium for automated testing :

  • Open-Source: Selenium's greatest strength, as previously said, is that it is a freeware and portable tool. There are no out-of-pocket expenses. The utility can be downloaded for free, and community-based help is also accessible.
  • Language assistance: Java, Perl, Python, C#, Ruby, Groovy, JavaScript, and other languages are supported by Selenium. It has its own script, yet it is not constrained by it. It can work with a variety of languages, depending on the developers' and testers' preferences.
  • Compatible with a variety of operating systems: Selenium may run on a variety of operating systems, including Windows, Mac OS X, Linux, and UNIX. A customized testing suite can be CONSTRUCTED on any platform and then executed on another using the Selenium suite of products. For example, you may write test cases in Windows and run them on a Linux system with ease.
  • Browser compatibility: Selenium is compatible with a variety of web browsers, including Internet Explorer, Chrome, Firefox, Opera, and Safari. When running tests and testing them across multiple browsers at the same TIME, this becomes really useful.
  • Programming languages and framework support: Selenium works with a variety of programming languages and frameworks. For source code compilation, it can, for example, integrate with ANT or Maven frameworks. It may also be used to test apps and generate reports using the TestNG framework. Continuous Integration (CI), can integrate with Jenkins or Hudson, and it can also integrate with other open-source tools to offer other functionalities.
  • Tests on a variety of devices: On Android, IPHONE, and Blackberry, Selenium Test Automation can be used to automate mobile web applications testing. This can aid in the generation of necessary results and the ongoing resolution of bugs present in the application.
  • Regular updates: Selenium support is based on a community, which allows for frequent updates and upgrades. These upgrades are simple to install and don't require any special training. Selenium is thus both resourceful and cost-effective.
  • Selenium suites with a lot of content: Selenium is more than just a single tool or utility; it's a full set of numerous testing tools that's why it's called a Suite. Each tool is tailored to specific testing needs and test environment constraints. Selenium also includes features such as Selenium IDE, Selenium Grid, and Selenium Remote Control (RC).
  • Ease with which it can be implemented: Selenium has a user-friendly interface that makes it simple to develop and perform tests. Its open-source capabilities allow users to script their own extensions, making them simple to CREATE, alter actions, and manipulate at a high level. Selenium's reporting features are also one of the reasons for its popularity, as it allows testers to extract results and take action based on them.
15.

What is automation testing, and what are its advantages?

Answer»

Automation testing or Test Automation is a process of automating the manual testing process of an application or a SYSTEM by using testing tools that ALLOW you to create scripts that can be executed repeatedly, generating detailed test reports of the application or system under test.

Advantages of Automated Testing are:

  • It supports both the performance and FUNCTIONAL testing of an application or system.
  • It facilitates the execution of repeated test cases.
  • It allows the parallel execution of the test cases.
  • It improves the accuracy and efficiency of the system by reducing the manual intervention of HUMANS to generate test cases.
  • It helps in testing a LARGE scale test matrix.
  • It saves valuable time and money for the testing team involved in the project.
16.

What is meant by Selenium Suite and what are its different components?

Answer»

Selenium is a package of several testing tools and is therefore often referred to as a Selenium Suite with each of these tools designed to CATER to a different testing requirement.

Following are the different components of Selenium Suite:

  • Selenium Integrated Development Environment (IDE): It is a Firefox/Chrome plug-in that is developed to speed up the creation of automation scripts by RECORDING the user actions on the web browser and exporting them as a reusable script.
  • Selenium Remote Control (RC): It is a SERVER that enables USERS to generate test scripts in their preferred programming language. It accepts commands from the test scripts and sends them to the browser as Selenium core JavaScript commands, for the browser to behave accordingly.
  • Selenium WebDriver: It is a programming interface that helps create and run test cases by directly communicating with the web browser and using its native compatibility to automate. Unlike RC, it doesn’t require an additional server to create and run test cases.
  • Selenium Grid: It allows parallel execution of tests on different browsers and operating systems by DISTRIBUTING commands to different machines simultaneously.