Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
E-Mail: appshells@gmail.com
Dear readers, these set of interview questions are designed in a way to help in cracking the automation testing
with Selenium Webdriver. In this document we will try to cover all those topics which we generally use with
Selenium Webdriver, such as Maven, TestNG etc.
To download the android application for Selenium Webdriver Interview Questions, follow the below link:
Selenium WebDriver Interview Questions Android Application
Ans: Selenium WebDriver is an open source web automation tool which provides support for multiple browser, platforms and
languages.
Brief History:
Selenium developed by Jason Huggins in 2004. Later in 2006 an engineer from Google named Simon Stewart started working on
WebDriver and thought to remove the limitation and merged Selenium with WebDriver in 2008, also known as Selenium 2.0. In 2009
Simon Stewart declared the reason why both of the projects were merged:
“Why are the projects merging? Partly because Webdriver addresses some shortcomings in selenium (for example, by being able to
bypass the JS sandbox, and we’ve got a gorgeous API), partly because selenium addresses some shortcomings in Webdriver (such as
supporting a broader range of browsers) and partly because the main selenium contributors and I felt that it was the best way to offer
users the best possible framework.”
1. Selenium 2: Also known as Selenium WebDriver, It supports the WebDriver API along with Selenium 1 technology underneath the
WebDriver API for maximum flexibility in porting tests. In addition, Selenium 2 still runs Selenium 1's Selenium RC interface for
backward compatibility.
2. Selenium 1: Also known as Selenium RC, It was the main Selenium project for a long time. Now Selenium 1 is deprecated and not
actively supported.
3. Selenium IDE: Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox
plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records
user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later
executed.
3. Why would you select Selenium as test tool for your project?
Ans: There are multiple reason to select Selenium as test tool for my project:
4. What are the different testing type we can perform with Selenium WebDriver?
E-Mail: appshells@gmail.com
6. What is Selenese?
Ans: Selenese is the language which is used to write scripts in Selenium IDE.
7. Mention five different types of exception you have encountered in Selenium WebDriver?
1. NoSuchElementException
2. WebDriverException
3. TimeoutException
4. NoSuchWindowException
5. StaleElementException
1. FirefoxDriver
2. ChromeDriver
3. IntenetExplorerDriver
4. HtmlUnitDriver
5. RemoteWebDriver
6. SafariDriver
7. WebDriverBackedSelenium
Ans: HTMLUnitDriver is fastest and most lightweight implementation of WebDriver. HTMLUnit does not execute test on Browser
but sends plain HTTP requests which makes test execution faster.
Pros:
1. Fastest implementation of WebDriver.
2. A pure Java implementation so it is platform independent.
3. Supports JavaScript.
Cons:
1. Emulates other Browser's JS behavior.
Ans: Selenium WebDriver makes direct calls to the browser using each browser's native support for automation. Whereas, Selenium-
RC injects JavaScript functions to the browser when it's loaded and then use JavaScript to drive the application under test.
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
Ans: Automation testing or Test Automation is a process to simulate user actions of application under test. Automation testing with
help of available testing tools such as, Selenium WebDriver helps in creating automated test scripts and reduces the execution time,
increases the efficiency and removes manual intervention.
Ans: From the Selenium IDE test scripts cab be exported in following languages:
1. Java
2. Python
3. Ruby
4. C#
13. What is the difference between "GET" and "NAVIGATE" to open a web page in selenium web driver?
Ans: Get method will get page to load, get a page source or get the text of an element whereas navigate will guide through history
like refresh, back and forward.
driver.quit(): It is used to shut down the Webdriver and close all instances associated to Webdriver.
Ans: There are largely three types of verification point in selenium Webdriver:
Ans : Assert: Assert command checks whether given condition is true or false and when it fails test will abort.
Verify: Verify command checks whether the given condition is true or false and will continue the execution whether it is true or false.
Ans: Locators can be termed as address to elements on the page, which makes possible to identify element uniquely on the page.
Ans: Following are the different types of locators available in Selenium WebDriver:
1. ID
2. Name
3. ClassName
4. Xpath
5. CSS Selector
6. LinkText
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
7. PartialLinkText
8. TagName
Ans: XPath, the XML path language, is a query language for selecting nodes from an XML document. It enables to traverse through
every node across the entire page and help in finding element with reference to another element on page.
Ans: Using the ID attribute is most preferable way to identify the element. W3C recommends that every developer should provide id
attribute to elements which are unique on the page. While processing the DOM (Document Object Model), browsers use id as the
preferred way to identify the element and this provides the fastest locator strategy.
Ans: findElement() and findElements() methods are used in selenium to locate the elements.
findElement(): The findElement() method returns a WebElement object based on a specified search criteria or throws up an exception
if it does not find any element matching the search criteria.
findElements(): The findElements() method returns a list of WebElements matching the search criteria. If no elements are found, it
returns an empty list.
22. What are different methods to locate elements with partial match?
Ans: CSSSelector and XPath provides a way to locate elements matching partial attribute values using following functions:
1. starts-with()
2. ends-with()
3. contains()
Ans: XPath axes helps to locate elements based on their relationship with another element. Following are few examples how to use
axes:
table:
Product Price Qty
product1 $100 12
product2 $200 3
1. ancestor: Selects all ancestors(parent, grandparent and so on) of the current node.
Eg: //td[text()='sksdroid']/ancestors::table
It will get the table element.
3. following: Selects everything in the document after the closing tag of the current node.
Eg: //td[text()='Product1']/following::tr
This will get the second row from the table.
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
5. preceding: Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes, and namespace
nodes.
Eg: //td[text()='$150']/preceding::tr
This will get the header row.
24. What are the ways to locate elements using advanced CSS Selectors?
Ans: Following are the some structural pseudo-classes which is used to locate elements:
1. :first-child
Eg: form#loginForm:first-child
this will locate the first element under the form.
2. last-child
Eg: form#loginForm:last-child
this will locate the last element under the form.
3. nth-child(2)
Eg: form#loginForm:nth-child(2)
this will locate the second child element under the form.
25. Can you show how to launch Firefox Webdriver instance and open google?
E-Mail: appshells@gmail.com
Ans: WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can
be buttons, drop boxes, checkboxes, radio buttons, labels etc.
1. isDisplayed()
2. isSelected()
3. isEnabled()
Example:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
Ans: getText() method is used to retrieve the inner text of the specified web element.
Eg:
String Text = driver.findElement(By.id(“Text”)).getText();
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
Ans: Value in the drop down can be selected using WebDriver’s Select class.
Example:
selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“Select_One”)));
selectByValue.selectByValue(“Android”);
selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“Select_Two”)));
selectByVisibleText.selectByVisibleText(“iOS”);
selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“Select_Three”)));
selectByIndex.selectByIndex(3);
Example:
driver.navigate().back();
2. navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.
Example:
driver.navigate().forward();
3. navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.
Example:
driver.navigate().refresh();
4. navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL.
Example:
driver.navigate().to(“https://google.com”);
Ans: driver.findElement(By.linkText(“Images”)).click();
The command finds the element using link text and then click on that element and thus the user would be re-directed to the
corresponding page.
The above mentioned link can also be accessed by using the following command.
driver.findElement(By.partialLinkText(“Ima”)).click();
The above command find the element based on the substring of the link provided in the parenthesis and thus partialLinkText()
finds the web element with the specified substring and then clicks on it.
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
40. How to find elements with same property and store it in a list?
Ans: Multiple elements having same attribute value on page can be located by using findElements() method and can be stored in a
list, find below the sample code for the same:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
WebDriver driver;
@BeforeTest
public void launchURL(){
driver = new FirefoxDriver();
driver.get("www.google.com");
}
@Test
public void findAllElements(){
List<WebElement> appsList = driver.findElements(By.xpath(".//*[@class='gb_o']"));
for(int i=0;i<appsList.size();i++){
System.out.println(appsList.get(i).getText());
}
}
@AfterTest
public void tearDown(){
driver.quit();
}
}
Ans: Selenium Webdriver uses browser's native support for automation (Which is different for every browser.), It controls the
browser from OS level. Selenium Webdriver architecture mainly divided into three parts:
1. Language Bindings
2. Selenium Webdriver API, and
3. Drivers
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
Selenium Webdriver supports various languages which can be used to implement the automation framework using Selenium
Webdriver API. Let’s say you have written code using Java bindings against the Selenium Webdriver API and that binding code will
issue commands across JSON wire protocol (This is a rest-base web service that is able to interpret those commands by manipulating
DOM elements on the page). Finally the driver (It is a executable which runs your tests on one of the driver) waiting for commands
executes it on specified browser.
Ans: The Webdriver API is the part of the system that you interact all the time while automating. The Webdriver API as compared to
Selenium RC API is different in many ways. This is now more manageable. This is made up of the Webdriver and the WebElement
objects.
driver.findElement(By.name("q"))
and
element.sendKeys("Hello World!!")
Ans: The WebDriver SPI stands for WebDriver Stateless Programming Interface, it is a mechanism that breaks down what the
element is, by using a unique ID, and then calling a command that is relevant. All the API calls above then call down.
driver.findElement(By.name("q"))
element.sendKeys("Hello World!!")
The above written code will look like when once it is in the SPI:
findElement(using="name", value="q")
sendKeys(element="webdriverID", value="Hello World!!")
Ans: The Webdriver developers created a transport mechanism called the JSON wire protocol. This protocol is able to transport all
the necessary elements to the code that controls it. It uses a REST like API as the way to communicate.
Ans: TestNG is an open-source automated testing framework inspired from Junit and Nunit but introducing some new functionalities
that make it more powerful and easier to use.
Functionalities such as use of annotations for dependency testing, test in groups, email-able reporting, multithreaded testing, data-
driven testing, flexible plugin API etc..
TestNG is designed to cover all categories of tests such as Unit, Functional, end-to-end and Integration.
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
Ans: TestNG.xml is a configuration file for managing the tests and also describes the runtime definition of a test suite. It allows
flexible configuration of the tests to be run. This file makes it easy to define all your test suites and their properties in one file. It is
always recommended to use testng.xml once your test become larger and requires configuration of multiple test at one place.
<test name="Regression1">
<classes>
<class name="test.sample.ParameterSample"/>
<class name="test.sample.ParameterTest"/>
<methods>
<include name="testMethod" />
</methods>
</classes>
</test>
</suite>
E-Mail: appshells@gmail.com
Ans: The parallel attribute on the <suite> tag can take one of following values:
TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect
the order that you specified.
TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows
you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking
advantage of TestNG using as many threads as possible to run your tests.
TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.
TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running
in different threads.
Ans: The timeout test in TestNG is time allotted to perform the testing. If the test fails to finish in that specified time limit, TestNG
will abandon the further testing and will mark it as failed.
Ans: Maven, a Yeddish word meaning 'accumulator of knowledge', was originally started as an attempt to simplify the build
processes in the Jakarta Turbine Project.
Definition: Maven is a project management and comprehension tool. Based on the concept of page object model (POM), maven can
manage a project's build, reporting and documentation.
Ans: Maven's primary goal is to allow a developer to comprehend the complete state of the development effort in the shortest period
of time. To attain this goal there are serveral areas of concern that Maven attempts to deal with:
E-Mail: appshells@gmail.com
1. Builds
2. Documentations
3. Reporting
4. SCMs
5. Release
6. Distribution
55. How can you say that maven uses convention over configuration?
Ans: "Convention over configuration (aka Coding by convention) is a software design paradigm which seeks to decrease the number
of decisions that developers need to make, gaining simplicity, but not necessarily losing the flexibility."
It is said that maven uses convention over configuration because in maven, developers are not required to create build process
themselves. Developers do not have to mention each and every configuration details.
Ans: POM or page object model is a fundamental unit of Maven. It is an XML file that contains information about the project and
configuration details used by maven to build the project. It resides in the base directory of the project as pom.xml.
1. Project dependencies
2. Plugins
3. Goals
4. Build profiles
5. Project version
6. Developers
7. Mailing list
Ans: An artifact is a file, usually a JAR, that gets deployed to a Maven repository. A maven build produces one or more artifacts,
such as a compiled JAR and source JAR.
Each artifact has a Group Id, an artifact Id and a version string. The three together uniquely identify the artifact.
59. What is Maven build life cycle and name three lifecycle of Maven.
Ans: A build lifecycle is a well-defined sequence of phases which define the order in which the goals are to be executed. Following
are the three lifecycles:
1. clean
2. default
3. site
Selenium Webdriver Interview Questions
Android App: https://goo.gl/NDkpj6
E-Mail: appshells@gmail.com
1. validate
2. complile
3. test
4. package
5. integration-test
6. verify
7. install
8. deploy
mvn –version
Please follow the below link and stay updated about new questions added in the interview kit.
To download the android application for Selenium Webdriver Interview Questions, follow the below link:
Selenium WebDriver Interview Questions Android Application
References:
http://www.seleniumhq.org/
http://testng.org/
https://maven.apache.org/