Q & A

Basic Selenium Interview Questions for Freshers

Selenium is a suite of tools designed for automated web testing. It includes:

  • Selenium WebDriver and RC: It offers APIs for different types of programming languages like .NET, Java, .
  • PHP, etc.
  • Selenium IDE (Integrated Development Environment): It is the tool for playing back and recording. It is mainly a Firefox plugin.
  • Selenium Grid: It allows you to distribute tests on multiple machines so that you can parallel run the tests. This helps in decreasing the time needed for running in the browser test suites.

Selenium 2.0 is a consolidated single tool that includes web testing tools Selenium WebDriver and Selenium RC.

This is a most updated version of Selenium that has released 2 beta versions with the changes mentioned below.

  • Beta 1 and Beta 2 updates (only for Java)
  • It supports Firefox through Mozilla’s Gekodriver
  • The minimum Java version is now 8+
  • System property webdriver.gecko.driver forces the server is the legacy or marionette Firefox driver more while ignoring the relatable desired capacity
  • Support for edge is offered by MS
  • Grid fixes NPE’s on the registration with unspecified browser
  • Update GeckoDriver-port arguments in different bindings
  • It also supports Safari on MacOS through the Safari driver of Apple

In Selenium, each control or object in the webpage is referred as the element. And there are several ways to find an element in the webpage. They are:

  • Name
  • ID
  • Attribute
  • Tag
  • Linktext
  • Xpath
  • CSS
  • PartialLink Text etc.

Selenium is used for web based application testing. Here the supported test types are:

  • Regression
  • Functional (get more information about functional testing)

Besides, Selenium is also used for post release validation with constant integration tool

  • Hudson
  • Jenkins
  • CruiseCont
  • Quick Build

Assertion is mainly a verification point that verifies the application status conforms to things that are expected. The main types of assertion are “verify”, “assert”, and “waitFor”.

The main use of X-path is to find the WebElement in the webpages. It is also important in identifying all the dynamic elements.

  • Double slash: Here you can start the selection matching anywhere in the document. It allows you to create “relative” path expressions.
  • Single slash: Here you can start the selection from the document node. And it will allow you to create “absolute” path expressions.

The main technical challenges with Selenium are:

  • It only supports the web-based applications
  • It doesn’t offer support to Bitmap comparison
  • No vendor support for tool is available compared to the commercial tools  like HP UFT
  • You need to depend on the third party tools for all the reporting related abilities
  • As no object repository concept is available in Selenium, therefore maintaining the objects often become difficult

Type keys would trigger JavaScript even in most of the cases whereas .type () won’t. Type key can populate the value attribute with JavaScript whereas the .type keys () emulates like actual user typing.

Assert: This command is used to check whether an element is on the page or not. If the asserted elements are unavailable, then the test would stop on the failed step. Or you can say that the test would be terminated at that point where check fails.

Verify: This command checks if the element is on the page. If not, then the test will perform executing. Here all the commands run guaranteed even in case the test fails.

A special kind of syntactic meta-data is added to the Java source code in Java, which is called as Annotations. Classes, variables, packages, parameters, and methods are annoted. The important Junit annotations that are very useful are:

  • Before
  • After
  • Test
  • Before class
  • After class
  • Ignore
  • RunWith

To click on any specific section of an element, you have to use the clickAT command. This command accepts the element locator and x, y coordinates as the arguments-clickAT (cordString, locator)

  • Selenium supports PHP, C#, Perl, Java, and Python.
  • It includes powerful methods for locating elements (DOM, Xpath, CSS)
  • It supports various OS such as Mac OS, Linux, and Windows
  • It has a highly developer community, which is supported by Google

Selenium is more prevalent than QTP as:

  • Selenium is open source where QTP works as a commercial tool.
  • Selenium is designed especially for web-based applications testing while QTP is used for client server application testing.
  • Selenium supports IE, Firefox, Safari, and Opera on different operating systems like Mac, Linux, Windows, etc. But QTP is only limited to Internet Explorer on Windows.
  • Selenium offers support to different programming languages like Perl, Ruby, Python where QTP only supports VB script.

There are four parameters that you need to pass in Selenium. These include:

  • Port number
  • Host
  • Browser
  • URL

The similarity is that both delay the execution speed. Now let’s check the differences.

Thread.sleep()- It stops the present (Java) thread for a specified time. It is performed only once. It takes one argument in integer format. For example: Thread.sleep()- This will wait for 2 seconds. And it only waits once at the command offered at sleep.

SetSpeed()- It is used to stop execution for each Selenium command for a particular amount of time. And it takes a single argument in the integer format. For example: Selenium.setSpeed (“2000”)- This will wait for 2 seconds. Each command that runs after setSpeed is delayed by the total number of milliseconds cited in setSpeed. This command is also very useful for the purpose of demonstration or if you use a slow web application.

The “Same Origin Policy” is used for security reasons and it ensures that your site’s content never becomes accessible by any script from another website. According to the policy, the codes located within the browser can operate with the domain of the website.

For avoiding “Same Origin Policy” a proxy injection method is used. In this mode, the Selenium server works as the client configured HTTP proxy that sits between the browser and the application under test and therefore it masks the AUT under the fictional URL.

The main purpose of heightened privileges is quite similar to proxy injection that allows the websites to perform something, which are not permitted usually. The main difference here is that here the browsers are launched in a special mode known as heightened privileges. Using this browser mode, Selenium core directly opens the AUT and can also read or write the content without passing the entire AUT through Selenium RC server.

You can choose “submit” method on the element to submit form- element.submit ()

Apart from that, you can select click method on the element that helps in form submission.

TestNG is a testing framework that is based on NUnit and JUnit for simplifying a wide range of testing requirements starting from Unit Testing to Integration Testing. The functionalities that make it an effective testing framework are:

  • Support for data-driven testing
  • Support for annotations
  • Ability to re-execute the failed test cases
  • Flexible test configurations

Explicit wait: It is a one-timer, used mainly for a specific search. It would try looking for the element again and again for a specific amount of time before throwing the NoSuchElementException. It would wait for the elements to show up.

Implicit wait: It sets a timeout for the successive Web Element searches.

You can use driver.findElements(By.xpath(“//iframe”))

This would return the list of frames.

Here you have to switch to every frame and look for the locator that you want. After that, break that loop.

Find elements (): It helps to find every element within the present page using the specified “locating mechanism. It returns a complete list of WebElement.

Find element (): It discovers the first element within the present page using the specified “locating mechanism. It returns the single WebElement.

The JUnits annotations linked with Selenium are:

  • Test public void method(): Annotations @Test identifies that this method is the test method environment.
  • Before public void method(): It performs the method() before every test. And this method can also prepare the test.
  • After public void method(): This annotation is used to perform a method before. The test method must start with test@Before
  • Keyword driven framework: This framework needs the development of keywords and data tables, independent on test automation. In case of keyword driven test, the application’s functionality under test is recognized in the table and also in stage by stage instructions for every test.
  • Data driven framework: Here the test data is separated and kept outside the Test Scripts, while the Test Case logic stays in the Test Scripts. The test data is read from the Excel Files (external files) and then they are loaded into the variables located inside the TestScript. The variables are used for both verification values and input values.

Pass the username and password with URL

Syntax: http://username:password@url

Ex: http:// creyate:tom@www.gmail.com

WebElement el = driver.findElement(By.id(“ElementID”))

//get test from element and stored in text variable

String text = el.getText();

//assert text from expected

Assert.assertEquals(“Element Text”, text);

  • Selenium is a free automation testing tool where Borland silk is not.
  • Selenium supports different browsers like Firefox, Internet Explorer, Opera, Safari, and so on where Borland Silk only supports Firefox and Internet Explorer.
  • Selenium suite is flexible enough to use different languages like Ruby, Java, Python, Perl, etc. But Silk Test only uses test scripting language
  • Selenium is only used for web application where Silk Test can also be used for client server applications

Object Repository is the important entity in the UI automations that allows the testers to store all the necessary objects that are used in scripts in a single or more than that centralized locations instead of being scattered all around the test scripts.

Selenium Grid works by sending the tests to the hub. Then those tests are redirected to Selenium Web Driver that launches the browser and then run the test. With the complete test suite, it allows to run tests in parallel.

Yes, but it can’t be used as effectively as the dedicated Performance Testing Tool like Loadrunner.

If you use Selenium Web Driver, there is no need to use Selenium Server as it is a completely different technology. Selenium Web Driver can make direct calls to the browsers using the native support of each browser for automation while Selenium RC needs the Selenium Server for injecting JavaScript into the browser. 

On the other hand, Selenium Server offers the functionality of Selenium RC that is used for Selenium 1.0 backwards compatibility.

Web Driver needs to be used when you need to improve support for handling pop ups, multiple frames, multiple alerts and browser windows, Ajax based UI elements, page navigation and drag and drop. Selenium 1.0 doesn’t properly support multi browser testing that includes improved functionality for browser.

Major limitation you can have when injecting capabilities is that the “findElement” command may not work as expected.

You can find the broken images in a page by using Selenium Web Driver by getting XPath and all the links in the page by using the tag name. Click on every link in the page and look for 404/500 in the target page title.

You can handle colors in Web Driver by using getCssValue(arg0) function to get the colors while sending “color” string as the argument.

Here is the method, which you can use for storing a value that is textbox by using WebDriver.

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

Webdrivers [ driver.switchTo().frame() ] method follows one of the three arguments when it comes to switching between the frames.

  • A name or ID: Choosing a frame by its name or ID
  • A number: Selecting the number by the index (zero based)

Previously found WebElement: Selecting the frame using the previously located WebElement.

In Selenium WebDriver, you can have 5 different types of exceptions. They are:

  • WebDriverException
  • NoSuchWindowException
  • NoAlertPresentException
  • TimeoutException
  • NoSuchElementException

It is possible to perform double click by using

Syntax- Actions act = new Actions (driver);


You can use “type”command for typing in the file input box of file upload. After that, you need to use “Robot” class in JAVA for making file upload in work.

The fastest WebDriver implementation is HTMLUnit Driver implementation. It doesn’t only execute tests on the browser but on simple HTTP request, which is quicker than launching browsers and implement the tests.

You can use the “SwitchTo” frame method for bringing control on the HTML frame- driver.switchTo().frame(“frameName”);

And you can use index number for specifying a frame.


It would bring control on the frame namely “frameName” of the 4th sub frame names “parentFrame”

Getwindowhandle(): It is used for getting the address of open browsers and here the return type is Set<String>

Getwindowhandles(): It is used for getting the address of the present browser where the return type and the control is string.

You can use method defaultContent ()Syntax-driver.switchTo().defaultContent(); for switching back from a frame.

The main types of locators are:

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

You can use the command echo <constant string> for displaying a constant string. And you can use the command echo ${variable name>> for displaying the value of a variable. Both are using PHP. In case you are using Java, then replacing eco with System.out.println

Recovery scenarios are based on the programming language that you use. For instance, if you are using Java, then you can use exception handling for overcoming the same. By using “Try Catch Block” within the Selenium WebDriver Java tests.

You can loop the features of the programming language for iterating through the options in test script. For instance, you can use “for” loop in Java to type different test data in a text book.

// test data collection in an array

String [ ] testData = { “test1” , “test2” , “test3” } ;

// iterate through each test data

For (string s: test data) { selenium.type ( “elementLocator”, testData) ; }

There are three ways through which you can prepare customized HTML report by using TestNG in hybrid framework. These are:

  • TestNG: using built-in default.html for getting the HTML report. XST also reports from Selenium, ANT. For converting XML content to HTML for using the customized reports using XSL jar.
  • TestNG combinations
  • Junit: With the help of ANT

For converting XML content to HTML for using the customized reports using XSL jar.

There are three ways to create HTML test report

  • TestNG: using built-in default.html for getting the HTML report. XST also reports from Selenium, ANT.
  • TestNG combinations
  • Junit: With the help of ANT

For converting XML content to HTML for using the customized reports using XSL jar.

To insert a break point in Selenium IDE, choose “Toggle break point” in Selenium IDE by right clicking on the command. Then press “B” on the keyboard and choose the command in Selenium IDE. It is possible to set in multiple break points in Selenium IDE.

Insert the break point from the location from where you want to perform the test step by step.

Run the test case. Execution would be paused at the given break point.

Click on the blue button to continue with the next statement.

Then click on the “Run” button for continuing executing different commands at a time.

Selenese is the Selenium set of command that is used for operating the test. There are mainly three types of Selenese.

  • Assertions: It is used as the check points.
  • Accessors: It is used for storing the values in the variable
  • Actions: It is used for performing interactions and operations with the target elements. 

The main limitations of Selenium IDE are:

  • Absence of exceptional handling
  • Selenium IDE only uses HTML languages
  • Selenium IDE doesn’t allow external databases reading
  • Selenium IDE doesn’t allow reading from the external files like .xls, .txt
  • Execution of branching or conditional statements like if, else, select statements is not possible.

Selenium IDE can either be opened in side bar or as the pop-up window.

There are 4 main locators used in Selenium. Namely:

  • Css Locators
  • X-Path Locators
  • HTML Name

Selenium IDE allows you to generate random numbers with the help of Java Script

Type css=input#sjavascript{Math.random()}

And for type css=input#sjavascript{new Date()}

You can use the Selenium IDE format option for converting tests into another programming language.

Yes, here you can use the “StoreTable” command.

For example, store text from cell 0,2 from an html table

Css=#table 0.2


  • When a locator changes and Selenium IDE fails to locate that element.
  • When the element that Selenium IDE was trying to access was not created
  • When the element that Selenium IDE was waiting to access did not come up on the webpage and the operation times out.

Insert the break point from the location where you want to execute it step by step. Then run the test case. The execution will pause at the mentioned break point. Click on the blue button to continue with the next step. And click on the run button to run commands at the same time.

There are two ways through which you can execute a Selenium IDE single line command.

Select “Execute this command” in Selenium IDE by right clicking the command

Press “X” key on the keyboard after choosing the command in Selenium IDE

The source view in Selenium IDE shows the script in XML format.

Selenium IDE can be set in two ways

Either you can press the “S” key on the keyboard and choose the command in Selenium IDE

Or right click on the command in Selenium IDE and then choose “Set / Clear Start Point”

You can use “Find Button” on Selenium IDE to test the locator. And when you click it, you will see on the screen that an element would be highlighted if the element locator is right. Otherwise, an error message would display.

The regular expression is the special text string designed for describing a search pattern. Regular expression in Selenium IDE is used with the keyword – regexp: as the prefix to the patterns and value that have to be added to the expected values.

A core extension is required when you want to extend the default functionality offered by Selenium Function Library. They are also known as “User Extension”. Besides, you can also download readymade core extension offered by other Selenium supporters.

For switching between windows, you can use the command “SelectWindow”. This command mainly uses the title of windows for identifying the right window to switch to.

You can use verifyElementPositionTop and verifyElementPositionLeft for this purpose. It offers a pixel comparison of the element’s position respectively from the top and left of the page.

You can use the StoreAlert command that would fetch the message of the alert pop up and then store it in the variable.

Selenium IDE has some limitations when it comes to offering language and browser support. But these limitations can be diminished by using Selenium RC. Selenium RC is mainly used for automating web applications on different web browsers and platforms with languages like C#, Java, Python, Perl, etc.

Being Java based, Selenium RC can interact with the web application by using any language. So, you can run the automation script against any web application and can bypass the restriction using the server.

Selenium IDE doesn’t offer direct support to functions like iteration, condition statements, handling unexpected errors, logging and reporting the test results and so on as IDE only supports HTML language. Selenium RC is used to deal with these issues as it supports languages like Ruby, Perl, PHP, Python, etc. And it can also write programs by using these languages for achieving the IDE issues. 

The main difference between Selenium RC and Selenium WebDriver is that the former injects JavaScript functions into the browsers when the page is loaded. And the latter drives the browser by using the inbuilt support of the browser.

The main advantages of Selenium RC are:

  • It can write or read data to/from .xls, .txt, etc
  • It can manage Ajax based UI elements and dynamic objects
  • It supports different operating systems and programming languages
  • The conditions and loops of Selenium RC can be used for better flexibility and performance
  • Selenium RC can be used for any JAVA script enabled browser

Frameworks are the collection of classes and libraries and they are useful when testers need to automate the test cases. JUnit, NUnit, RSpec, Bromine, TestNG, unittest are some of the major frameworks found in RC.

Use the “SelectWindow” method to manage pop-ups in RC. Here a pop-up window would be selected and Window Focus method will allow the control to the pop-up windows from the present window. And it will perform actions as per the script.

Except for the restriction of “Same Origin Policy” from JS, Selenium is also restricted from performing anything, which is outside the browser.

Yes you can when you don’t use JAVA testing framework. TestNG lets you do this if you use JAVA client driver of Selenium instead of using JAVA testing framework. With the help of the “parallel=test” attribute, you can set the tests, which can be performed in parallel and can describe two different types of tests, each of them using different browser.

When you want complete automation against different client platforms and server, you have to find a way to invoke the tests from a command line method so that the reports can inform what happened and offer flexibility in creating the test suites. TestNG offers you that flexibility.

For capturing server side log in Selenium server, you need to use command- java –jar .jar –log selenium.log

It is possible to run Selenium server on java-jar selenium-server.jar-port except for the default port 4444.

Selenium grid hub keeps polling the RC slaves at predefined time for ensuring it is available for testing. This parameter is known as “remoteControlPollingIntervalSeconds” and is described in “grid_configuration.yml”file”

You can use driver.manage.pageloadingtime for handling network latency.

You can use command sendkeys() for entering values onto text boxes

For identifying an object using Selenium, you can use:

  • isElementPresent takes a locator as the argument and if found returns a Boolean
  • isElementPresent(String locator)
  • Startpoints: This indicates the point from where execution needs to begin. Startpoint can also be used when the user likes to operate the testscript from a breakpoint or from the middle of a code.
  • Breakpoints: The execution will stop instantly when a breakpoint is implemented in the code. It will help you in verifying that the code is working as estimated.
  • JAVA programs run slowly than Python programs
  • JAVA uses static typing where Python is typed dynamically
  • JAVA uses conventional braces for starting and ending blocks while Python uses indentation
  • Python is more compact and simpler than JAVA

Handling Ajax call using “pause” command is not very reliable. Long pause time can make the test very slow while increasing the testing time. As an alternative “waitforcondition” will help more in testing Ajax applications.

But it is tough to assess the risk that comes with a specific Ajax application. Offering complete freedom to the developers for modifying Ajax applications make the process of testing even more challenging. At the same time, creating automated test request for testing tools like Ajax may be difficult. It is because Ajax applications often use various types of serialization or encoding techniques for submitting POST data. 

It is an IDE, which helps people to write faster and better code for Selenium. IntelliJ can also be used in the option to Eclipse and JAVA bean.

TestNG report can be customized in two ways

  • By using IReporter Interface
  • By using ITestListener Interface

You will need JAVA API IText for generating PDF reports

In Selenium WebDriver, the Listeners “listen” to the event described in the Selenium script and then behave accordingly. It also helps to customize TestNG logs or reports. In Selenium WebDriver, there are two major Listeners, namely:

TestNG Listeners and WebDriver Listeners

  • IAnnotationTransformer
  • IAnnotationTransformer2
  • IConfigurationListener
  • IConfigurable
  • IHookable
  • IExecutionListener
  • IInvokedMethodListener
  • IInvokedMethodListener2
  • IReporter
  • IMethodInterceptor
  • ITestListener
  • ISuiteListener

Desired capability is the series of value/key pairs, which store the browser properties like browser version, browser name, the path of browser driver available in the system, etc. for deciding the browser’s behavior at run time.

For Selenium, desired capability can also be used for configuring the driver instance of Selenium WebDriver when you decide to run the test cases on various browsers with various versions and operating systems.

You need JDBC (Java Database Connectivity) API for database testing in Selenium WebDriver. It lets you execute the SQL statements.

Selenium can automate web-based applications on various browsers. But AutoIT helps in handling the non-HTML popups and window GUI in the application.

Session handling is important when working with Selenium. It is because during test execution, Selenium WebDriver needs to interact with the browser always to perform the mentioned commands. During execution, there is also a chance that before the present execution completes, someone else starts executing another script in the same type of browser and in the same machine. Session handling helps to avoid these scenarios.

The main advantages of using Git Hub for Selenium are:

  • It allows multiple people working on the same project to update the project details and simultaneously inform other team members.
  • Jenkins also helps to develop the project regularly from the remote repository. And it helps you to maintain a track of the failed builds.