SELENIUM NOTES
Q #1) What is Automation Testing?
Automation testing is a process of automating the manual process to test the application under test.
Automation testing involves use to a separate testing tool which lets you create test scripts which
can be executed repeatedly and doesn’t require any manual intervention.
Q #2) What are the benefits of Automation Testing?
Benefits of Automation testing are:
1. Supports execution of repeated test cases
2. Aids in testing a large test matrix
3. Enables parallel execution
4. Encourages unattended execution
5. Improves accuracy thereby reducing human generated errors
6. Saves time and money
Q #3) Why should Selenium be selected as a test tool?
1. Selenium is free and open source
2. Selenium have a large user base and helping communities
3. Selenium have cross Browser compatibility (Firefox, chrome, Internet Explorer, Safari etc.)
4. Selenium have great platform compatibility (Windows, Mac OS, Linux etc.)
5. Selenium supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.)
6. Selenium has fresh and regular repository developments
7. Selenium supports distributed testing
Q #4) What is Selenium? What are the different Selenium components?
Selenium is one of the most popular automated testing suites. Selenium is designed in a way to
support and encourage automation testing of functional aspects of web based applications and a
wide range of browsers and platforms. Due to its existence in the open source community, it has
become one of the most accepted tools amongst the testing professionals.
Selenium is not just a single tool or a utility, rather a package of several testing tools and for the
same reason it is referred to as a Suite. Each of these tools is designed to cater different testing and
test environment requirements.
The suite package constitutes of the following sets of tools:
Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and
playback tool. It is distributed as a Firefox Plugin.
Selenium Remote Control (RC) – Selenium RC is a server that allows user to create test
scripts in a desired programming language. It also allows executing test scripts within the
large spectrum of browsers.
Selenium WebDriver – WebDriver is a different tool altogether that has various advantages
over Selenium RC. WebDriver directly communicates with the web browser and uses its
native compatibility to automate.
Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms
and environments concurrently.
Q #5) What are the testing types that can be supported by Selenium?
Selenium supports the following types of testing:
Selenium Notes Page 2
1. Functional Testing
2. Regression Testing
Q #6) What are the limitations of Selenium?
Following are the limitations of Selenium:
Selenium supports testing of only web based applications
Mobile applications cannot be tested using Selenium
Captcha and Bar code readers cannot be tested using Selenium
Reports can only be generated using third party tools like TestNG or Junit.
As Selenium is a free tool, thus there is no ready vendor support though the user can find
numerous helping communities.
User is expected to possess prior programming language knowledge.
Q #7) What is the difference between Selenium IDE, Selenium RC and WebDriver?
Feature Selenium IDE Selenium RC WebDriver
Browser Selenium IDE comes as a Selenium RC supports a varied WebDriver supports a varied
Compatibility Firefox plug-in, thus it range of versions of Mozilla range of versions of Mozilla
supports only Firefox Firefox, Google Chrome, Firefox, Google Chrome,
Internet Explorer and Opera Internet Explorer and Opera.
Also supports
HtmlUnitDriver which is a
GUI less or headless
browser.
Record and Selenium IDE supports Selenium RC doesn't supports WebDriver doesn't support
Playback record and playback record and playback feature record and playback feature
feature
Server Selenium IDE doesn't Selenium RC requires server to WebDriver doesn't require
Requirement require any server to be be started before executing the any server to be started
started before executing test scripts before executing the test
the test scripts scripts
Architecture Selenium IDE is a Selenium RC is a JavaScript WebDriver uses the
Javascript based based Framework browser's native
framework compatibility to automation
Object Oriented Selenium IDE is not an Selenium RC is semi object WebDriver is a purely object
object oriented tool oriented tool oriented tool
Dynamic Finders Selenium IDE doesn't Selenium RC doesn't support WebDriver supports dynamic
(for locating web support dynamic finders dynamic finders finders
elements on a
webpage)
Handling Alerts, Selenium IDE doesn't Selenium RC doesn't explicitly WebDriver offers a wide
Navigations, explicitly provides aids to provides aids to handle alerts, range of utilities and classes
Dropdowns handle alerts, navigations, navigations, dropdowns that helps in handling alerts,
Selenium Notes Page 3
Feature Selenium IDE Selenium RC WebDriver
dropdowns navigations, and dropdowns
efficiently and effectively.
WAP Selenium IDE doesn't Selenium RC doesn't support WebDriver is designed in a
(iPhone/Android) support testing of testing of iPhone/Andriod way to efficiently support
Testing iPhone/Andriod applications testing of iPhone/Android
applications applications. The tool comes
with a large range of drivers
for WAP based testing.
For example, AndroidDriver,
iPhoneDriver
Listener Support Selenium IDE doesn't Selenium RC doesn't support WebDriver supports the
support listeners listeners implementation of Listeners
Speed Selenium IDE is fast as it is Selenium RC is slower than WebDriver communicates
plugged in with the web- WebDriver as it doesn't directly with the web
browser that launches the communicates directly with the browsers. Thus making it
test. Thus, the IDE and browser; rather it sends much faster.
browser communicates selenese commands over to
directly Selenium Core which in turn
communicates with the
browser.
Q #8) When should I use Selenium IDE?
Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and
playback feature makes it exceptionally easy to learn with minimal acquaintances to any
programming language. Selenium IDE is an ideal tool for a naïve user.
Q #9) What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
Q #10) What are the different types of locators in Selenium?
Locator can be termed as an address that identifies a web element uniquely within the webpage.
Thus, to identify web elements accurately and precisely we have different types of locators in
Selenium:
ID
ClassName
Name
TagName
LinkText
PartialLinkText
Xpath
CSS Selector
DOM
Selenium Notes Page 4
Q #11) What is difference between assert and verify commands?
Assert: Assert command checks whether the given condition is true or false. Let’s say we assert
whether the given element is present on the web page or not. If the condition is true then the
program control will execute the next test step but if the condition is false, the execution would stop
and no further test would be executed.
Verify: Verify command also checks whether the given condition is true or false. Irrespective of the
condition being true or false, the program execution doesn’t halts i.e. any failure during verification
would not stop the execution and all the test steps would be executed.
Q #12) What is an Xpath?
Xpath is used to locate a web element based on its XML path. XML stands for Extensible Markup
Language and is used to store, organize and transport arbitrary data. It stores data in a key-value
pair which is very much similar to HTML tags. Both being markup languages and since they fall under
the same umbrella, Xpath can be used to locate HTML elements.
The fundamental behind locating elements using Xpath is the traversing between various elements
across the entire page and thus enabling a user to find an element with the reference of another
element.
Q #13) What is the difference between “/” and “//” in Xpath?
Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be
created to start selection from the document node/start node.
Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be
created to start selection from anywhere within the document.
Q #14) What is Same origin policy and how it can be handled?
The problem of same origin policy disallows to access the DOM of a document from an origin that is
different from the origin we are trying to access the document.
Origin is a sequential combination of scheme, host and port of the URL. For example, for a URL
http:// [Link] the origin is a combination of http,
[Link], 80 correspondingly.
Thus the Selenium Core (JavaScript Program) cannot access the elements from an origin that is
different from where it was launched. For Example, if I have launched the JavaScript Program from
“[Link] then I would be able to access the pages within the same
domain such as “[Link] or
“[Link] The other domains like [Link],
[Link] would no more be accessible.
So, In order to handle same origin policy, Selenium Remote Control was introduced.
Q #15) When should I use Selenium Grid?
Selenium Grid can be used to execute same or different test scripts on multiple platforms and
browsers concurrently so as to achieve distributed test execution, testing under different
environments and saving execution time remarkably.
Q #16) What do we mean by Selenium 1 and Selenium 2?
Selenium Notes Page 5
Selenium RC and WebDriver, in a combination are popularly known as Selenium 2. Selenium RC
alone is also referred as Selenium 1.
Q #17) Which is the latest Selenium tool?
WebDriver
Q #18) How do I launch the browser using WebDriver?
The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
Q #19) What are the different types of Drivers available in WebDriver?
The different drivers available in WebDriver are:
FirefoxDriver
InternetExplorerDriver
ChromeDriver
SafariDriver
OperaDriver
AndroidDriver
IPhoneDriver
HtmlUnitDriver
Q #20) What are the different types of waits available in WebDriver?
There are two types of waits available in WebDriver:
1. Implicit Wait
2. Explicit Wait
Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between
each consecutive test step/command across the entire test script. Thus, subsequent test step would
only execute when the 30 seconds have elapsed after executing the previous test step/command.
Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or
the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular
instance only.
Q #21) How to type in a textbox using Selenium?
User can use sendKeys(“String to be entered”) to enter the string in the textbox.
Syntax:
WebElement username = [Link]([Link](“Email”));
// entering username
[Link](“sth”);
Q #22) How can you find if an element in displayed on the screen?
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()
Syntax:
Selenium Notes Page 6
isDisplayed():
boolean buttonPresence = [Link]([Link](“gbqfba”)).isDisplayed();
isSelected():
boolean buttonSelected = [Link]([Link](“gbqfba”)).isDisplayed();
isEnabled():
boolean searchIconEnabled = [Link]([Link](“gbqfb”)).isEnabled();
Q #23) How can we get a text of a web element?
Get command is used to retrieve the inner text of the specified web element. The command doesn’t
require any parameter but returns a string value. It is also one of the extensively used commands for
verification of messages, labels, errors etc displayed on the web pages.
Syntax:
String Text = [Link]([Link](“Text”)).getText();
Q #24) How to select value in a dropdown?
Value in the drop down can be selected using WebDriver’s Select class.
Syntax:
Select DropdownValue = new Select ([Link]([Link]("XPath/ID")));
[Link](OCType);
Or
[Link](2);
Q #25) What are the different types of navigation commands?
Following are the navigation commands:
navigate().back() – The above command requires no parameters and takes back the user to the
previous webpage in the web browser’s history.
Sample code:
[Link]().back();
navigate().forward() – This command lets the user to navigate to the next web page with reference
to the browser’s history.
Sample code:
[Link]().forward();
navigate().refresh() – This command lets the user to refresh the current web page there by reloading
all the web elements.
Sample code:
[Link]().refresh();
navigate().to() – This command lets the user to launch a new web browser window and navigate to
the specified URL.
Sample code:
[Link]().to(“[Link]
Q #26) How to click on a hyper link using linkText?
[Link]([Link](“Google”)).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.
Selenium Notes Page 7
[Link]([Link](“Goo”)).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.
Q #27) How to handle frame in WebDriver?
An inline frame acronym as iframe is used to insert another document with in the current HTML
document or simply a web page into a web page by enabling nesting.
Select iframe by id
[Link]().frame(“ID of the frame“);
Locating iframe using tagName
[Link]().frame([Link]([Link](“iframe”).get(0));
Locating iframe using index
frame(index)
[Link]().frame(0);
frame(Name of Frame)
[Link]().frame(“name of the frame”);
frame(WebElement element)
Select Parent Window
[Link]().defaultContent();
Q #28) When do we use findElement() and findElements()?
findElement(): findElement() is used to find the first element in the current web page matching to
the specified locator value. Take a note that only first matching element would be fetched.
Syntax:
WebElement element =[Link]([Link](“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to
the specified locator value. Take a note that all the matching elements would be fetched and stored
in the list of WebElements.
Syntax:
List <WebElement> elementList =[Link]([Link](“//div[@id=’example’]//ul//li”));
Q #29) How to find more than one web element in the list?
At times, we may come across elements of same type like multiple hyperlinks, images etc arranged
in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single
piece of code and this can be done using WebElement List.
Sample Code
// Storing the list
1List <WebElement> elementList = [Link]([Link]("//div[@id='example']//ul//li"));
// Fetching the size of the list
int listSize = [Link]();
for (int i=0; i<listSize; i++)
{
Selenium Notes Page 8
// Clicking on each service provider link
[Link](i).click();
// Navigating back to the previous page that stores link to service providers
[Link]().back();
}
Q #30) What is the difference between [Link]() and [Link] command?
close(): WebDriver’s close() method closes the web browser window that the user is currently
working on or we can also say the window that is being currently accessed by the WebDriver. The
command neither requires any parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the windows that the program has
opened. Same as close() method, the command neither requires any parameter nor does is return
any value.
Q #31) Can Selenium handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing. Therefore,
windows pop up cannot be handled using Selenium.
Q #32) How can we handle web based pop up?
WebDriver offers the users with a very efficient way to handle these pop ups using Alert interface.
There are the four methods that we would be using along with the Alert interface.
• void dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop up
window appears.
• void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window
appears.
• String getText() – The getText() method returns the text displayed on the alert box.
• void sendKeys(String stringToSend) – The sendKeys() method enters the specified string
pattern into the alert box.
Syntax:
// accepting javascript alert
Alert alert = [Link]().alert();
[Link]();
#33) How can we handle windows based pop up?
Selenium is an automation testing tool which supports only web application testing, that means, it
doesn’t support testing of windows based applications. However Selenium alone can’t help the
situation but along with some third party intervention, this problem can be overcome. There are
several third party tools available for handling window based pop ups along with the selenium like
AutoIT, Robot class etc.
Q #34) How to assert title of the web page?
//verify the title of the web page
assertTrue(“The title of the window is incorrect.”,[Link]().equals(“Title of the page”));
Q #35) How to mouse hover on a web element using WebDriver?
WebDriver offers a wide range of interaction utilities that the user can exploit to automate mouse
and keyboard events. Action Interface is one such utility which simulates the single user interactions.
Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down
which then opens a list of options.
Sample Code:
Selenium Notes Page 9
1 // Instantiating Action Interface
2 Actions actions=new Actions(driver);
3 // howering on the dropdown
4 [Link]([Link]([Link]("id of the dropdown"))).perform();
5 // Clicking on one of the items in the list options
6 WebElement subLinkOption=[Link]([Link]("id of the sub link"));
7 [Link]();
Q #36) How to retrieve css properties of an element?
The values of the css properties can be retrieved using a get() method:
Syntax:
[Link]([Link](“id“)).getCssValue(“name of css attribute”);
[Link]([Link](“id“)).getCssValue(“font-size”);
Q #37) How to capture screenshot in WebDriver?
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class CaptureScreenshot
{
WebDriver driver;
@Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
[Link]("[Link]
}
@After
public void tearDown() throws Exception
{
[Link]();
}
@Test
public void test() throws IOException
{
// Code to capture the screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs([Link]);
// Code to copy the screenshot in the desired location
[Link](scrFile, newFile("C:\\CaptureScreenshot\\[Link]"));
}
}
Selenium Notes Page 10
Q #38) What is Junit?
Junit is a unit testing framework introduced by Apache. Junit is based on Java.
Q #39) What are Junit annotations?
Following are the Junit Annotations:
• @Test: Annotation lets the system know that the method annotated as @Test is a test
method. There can be multiple test methods in a single test script.
• @Before: Method annotated as @Before lets the system know that this method shall be
executed every time before each of the test method.
• @After: Method annotated as @After lets the system know that this method shall be
executed every time after each of the test method.
• @BeforeClass: Method annotated as @BeforeClass lets the system know that this method
shall be executed once before any of the test method.
• @AfterClass: Method annotated as @AfterClass lets the system know that this method shall
be executed once after any of the test method.
• @Ignore: Method annotated as @Ignore lets the system know that this method shall not be
executed.
Q #40) What is TestNG and how is it better than Junit?
TestNG is an advance framework designed in a way to leverage the benefits by both the developers
and testers. With the commencement of the frameworks, JUnit gained an enormous popularity
across the Java applications, Java developers and Java testers with remarkably increasing the code
quality. Despite being easy to use and straightforward, JUnit has its own limitations which give rise
to the need of bringing TestNG into the picture. TestNG is an open source framework which is
distributed under the Apache software License and is readily available for download.
TestNG with WebDriver provides an efficient and effective test result format that can in turn be
shared with the stake holders to have a glimpse on the product’s/application’s health thereby
eliminating the drawback of WebDriver’s incapability to generate test reports. TestNG has an inbuilt
exception handling mechanism which lets the program to run without terminating unexpectedly.
There are various advantages that make TestNG superior to JUnit. Some of them are:
• Added advance and easy annotations
• Execution patterns can set
• Concurrent execution of test scripts
• Test case dependencies can be set
Q #41) How to set test case priority in TestNG?
Setting Priority in TestNG
Code Snippet
1 package TestNG;
2 import [Link].*;
3 public class SettingPriority {
4 @Test(priority=0)
5 public void method1() {
6 }
7 @Test(priority=1)
8 public void method2() {
9 }
10 @Test(priority=2)
11 public void method3() {
12 }
13 }
Selenium Notes Page 11
Test Execution Sequence:
1. Method1
2. Method2
3. Method3
Q #42) What is a framework?
Framework is a constructive blend of various guidelines, coding standards, concepts, processes,
practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar
automation testing.
Q #43) What are the advantages of Automation framework?
Advantage of Test Automation framework
• Reusability of code
• Maximum coverage
• Recovery scenario
• Low cost maintenance
• Minimal manual intervention
• Easy Reporting
Q #44) What are the different types of frameworks?
Below are the different types of frameworks:
1. Module Based Testing Framework: The framework divides the entire “Application Under
Test” into number of logical and isolated modules. For each module, we create a separate and
independent test script. Thus, when these test scripts taken together builds a larger test script
representing more than one module.
2. Library Architecture Testing Framework: The basic fundamental behind the framework is to
determine the common steps and group them into functions under a library and call those functions
in the test scripts whenever required.
3. Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate
the test script logic and the test data from each other. It lets the user store the test data into an
external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used
to access and populate the data within the test scripts.
4. Keyword Driven Testing Framework: The Keyword driven testing framework is an extension
to Data driven Testing Framework in a sense that it not only segregates the test data from the
scripts, it also keeps the certain set of code belonging to the test script into an external data file.
5. Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one
above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of
all kinds of associated frameworks.
6. Behavior Driven Development Framework: Behavior Driven Development framework allows
automation of functional validations in easily readable and understandable format to Business
Analysts, Developers, Testers, etc.
Q #45) How can I read test data from excels?
Test data can efficiently be read from excel using JXL or POI [Link] detailed tutorial here.
Selenium Notes Page 12
Q #46) What is the difference between POI and jxl jar?
# JXL jar POI jar
1 JXL supports “.xls” format i.e. binary based format. JXL POI jar supports all of these formats
doesn’t support Excel 2007 and “.xlsx” format i.e. XML
based format
2 JXL API was last updated in the year 2009 POI is regularly updated and
released
3 The JXL documentation is not as comprehensive as that of POI has a well prepared and highly
POI comprehensive documentation
4 JXL API doesn’t support rich text formatting POI API supports rich text
formatting
5 JXL API is faster than POI API POI API is slower than JXL API
Q #47) What is the difference between Selenium and QTP?
Feature Selenium Quick Test Professional (QTP)
Browser Selenium supports almost all the popular QTP supports Internet Explorer,
Compatibility browsers like Firefox, Chrome, Safari, Firefox and Chrome. QTP only
Internet Explorer, Opera etc supports Windows Operating System
Distribution Selenium is distributed as an open QTP is distributed as a licensed tool
source tool and is freely available and is commercialized
Application Selenium supports testing of only web QTP supports testing of both the web
under Test based applications based application and windows based
application
Object Object Repository needs to be created as QTP automatically creates and
Repository a separate entity maintains Object Repository
Language Selenium supports multiple QTP supports only VB Script
Support programming languages like Java, C#,
Ruby, Python, Perl etc
Vendor Support As Selenium is a free tool, user would not Users can easily get the vendor’s
get the vendor’s support in support in case of any issue
troubleshooting issues
Q #48) Can WebDriver test Mobile applications?
Selenium Notes Page 13
WebDriver cannot test Mobile applications. WebDriver is a web based testing tool, therefore
applications on the mobile browsers can be tested.
Q #49) Can captcha be automated?
No, captcha and bar code reader cannot be automated.
Q #50) What is Object Repository? How can we create Object Repository in Selenium?
Object Repository is a term used to refer to the collection of web elements belonging to Application
Under Test (AUT) along with their locator values. Thus, whenever the element is required within the
script, the locator value can be populated from the Object Repository. Object Repository is used to
store locators in a centralized location instead of hard coding them within the scripts.
In Selenium, objects can be stored in an excel sheet which can be populated inside the script
whenever required.
Q #51) Difference between Absolute path & Relative path.
Absolute path will start with root path (/) and Relative path will from current path (//)
Q #52) Tell me some TestNG Annotations.
@Test,@Parameters,@Listeners,@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest,
@DataProvider,@BeforeGroups,@AfterGroups,@BeforeClass,@AfterClass,
@BeforeMethod,@AfterMethod,@Factory
Q #53) What are desired capabilities?
Desired Capabilities help to set properties for the Web Driver. A typical use case would be to
set the path for the Firefox Driver if your local installation doesn't correspond to the default
settings.
Q #54) Difference between Selenium RC and Selenium
Web driver.
Selenium RC Selenium Web driver
Selenium RC’s architecture is way more complicated.
Web Driver’s architecture is simpler than
Selenium RC’s.
Selenium RC is slower since it uses a JavaScript Web Driver is faster than Selenium RC since
program called Selenium [Link] Selenium Core is it speaks directly to the browser uses the
the one that directly controls the browser, not you. browser’s own engine to control it.
Selenium Core, just like other JavaScript codes, can Web Driver interacts with page elements in a
access disabled elements. more realistic way.
Web Driver’s API is simpler than Selenium
Selenium RC’s API is more matured but contains
RC’s. It does not contain redundant and
redundancies and often confusing commands.
confusing commands.
Selenium RC cannot support the headless HtmlUnit Web Driver can support the headless
browser. It needs a real, visible browser to operate on. HtmlUnit browser.
Selenium RC Has Built-In Test Result Generator. Web Driver has no built-in command that
Selenium Notes Page 14
Selenium RC automatically generates an HTML file of
automatically generates a Test Results File.
test results.
Selenium RC needs the help of the RC Server in order
web Driver directly talks to the browser
to do so.
Selenium RC can support new browsers It cannot readily support new browsers
Q #55) Difference between Web driver listener and
TestNG Listener.
TestNG and Web driver Listener have different interfaces to implement and call them. They both
modify respective behaviour. You can use Listeners in Annotation. Below 2 URL gives the
detailed list of listener and their interfaces.
Q #56) Describe your framework.
Q #57) Which is the best way to locate an element?
Finding elements by ID is usually going to be the fastest option, because at its root, it eventually calls
down to [Link](), which is optimized by many browsers.
Finding elements by XPath is useful for finding elements using very complex selectors, and is the
most flexible selection strategy, but it has the potential to be very slow, particularly in IE. In IE 6, 7,
or 8, finding by XPath can be an order of magnitude slower than doing the same in Firefox. IE
provides no native XPath-over-HTML solution, so the project must use a JavaScript XPath
implementation, and the JavaScript engine in legacy versions of IE really is that much slower.
If you have a need to find an element using a complex selector, I usually recommend using CSS
Selectors, if possible. It's not quite as flexible as XPath, but will cover many of the same cases,
without exhibiting the extreme performance penalty on IE that XPath can.
Q #58) Why we refer Firefox driver to the web driver
inheritance.
web Driver driver = new FireFoxDriver();
WebDriver is an interface which contain several abstract methods such as get(...), findElamentBy(...)
etc.
We simply create reference of web Driver and we can assign objects (Firefox driver, CromeDriver,
IEDriver, Andriod driver etc) to it.
Ex :
WebDriver driver = new FireFoxDriver();-----------(1)
If we are using (1) we can do the same thing by using
FireFoxDriver driver = new FireFoxDriver();---------(2)
We can use (1) and (2) for same purpose but if we want to switch to another browser in same
program
then again we have to create the object of other class as for example
CromeDriver driver = new CromeDriver();.
Selenium Notes Page 15
creating object of several class is not good. So we create the reference of WebDriver and
we assign the objects of another class as for example
WebDriver driver; // it is created only one time in the program
driver = new FireFoxDriver();// any where in the program
driver = new CromeDriver(); // any where in the program
Q #59) What are the features of TestNG?
TestNG is a testing framework designed to simplify a broad range of testing needs, from
unit testing (testing a class in isolation of the others) to integration testing (testing entire
systems made of several classes, several packages and even several external frameworks,
such as application servers). You can use test suite,annotations, automatically generation
of report and much more.
Q #60) What is the difference between [Link]()
and selenium. Set Speed ("2000")?
If the application is taking time to load the page then we use [Link](" "). This
command is doesn’t wait upto the given time whenever the page load is completed.
If the application is taking time to refresh the page, then we use Thread. Sleep ( ).it is a standard wait
it simply wait to the given time.
[Link]
1. Takes a single argument in string format
Ex: [Link]("2000") - will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in set
Speed.
[Link]
1. Takes a single argument in integer format
ex: thread. Sleep(2000) - will wait for 2 seconds
2. Waits for only once at the command given at sleep.
Q #61) In what situation selenium finding element
get fails?
· Element loading issue
· Dynamic id of web element
Q #62) What is the difference between "GET" and "NAVIGATE" to open a web page in selenium
web driver?
Get method will get a page to load or get page source or get text that's all whereas navigate
will guide through the history like refresh, back, [Link] example if we want to move
forward and do some functionality and back to the home page this can be achieved
through navigate() only. [Link] will wait till the whole page gets loaded and [Link]
will just redirect to that page and will not wait
Q #63) Please tell me the difference b/w implicitly Wait and Explicit wait.
Selenium Notes Page 16
Implicit Wait sets internally a timeout that will be used for all consecutive Web Element searches. It
will try lookup the element again and again for the specified amount of time before throwing a
NoSuchElementException if the element could not have been found. It does only this and can't be
forced into anything else - it waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more extendible in
the means that you can set it up to wait for any condition you might like. Usually, you can use some
of the prebuilt Expected Conditions to wait for elements to become clickable, visible, invisible, etc.,
or just write your own condition that suits your needs.
Q #64) How we can retrieve the dynamically changing Ids?
When we login Facebook the login label's id changes dynamically thus resulting in failure.
We have a hierarchy of locators and Facebook Is dynamic in nature,so we are not able to
use "id" for identification for after that we have remaining 7 locator's for that :2. xpath ()..
3. name..4. css.. 5. link text.. 6. partiallinktext...[Link] name. so u can use any one for
identifying it. Most probably u can use "xpath" or "css-locator" and if there r tag then
link text or partial-link text. it depend on u . But we never use id's in Ajax application
because it’s not possible.
Q #65) What is the difference between [Link]() and [Link] () method?
Close() - It is used to close the browser or page currently which is having the focus.
Quit() - It is used to shut down the web driver instance or destroy the web driver instance
(Close all the windows)
Q #66) How to scroll web element?--not browser—
FirefoxProfile profile=new FirefoxProfile();
[Link](true);
WebDriver driver=new FirefoxDriver(profile);
[Link]("[Link]
[Link](6000L);
WebElement element=[Link]([Link]("//div[@id='draggable']"));
Actions actn=new Actions(driver);
[Link](element, 50, 50).build().perform();
}
Q #67) What is the basic use of Firefox profiles and how can we use them using selenium?
A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords,
and history; in short, all of your personal settings.
We use them to change user agent, changing default download directory, changing versions etc.
Q #68) Customize the name of file going to be downloaded?
You have to download AUTO [Link] file and has to be install
Selenium Notes Page 17
and later you have create .au3 file (in this file you have to specify the commands in
VB script like your file name, where have to save, it will be easy may be 3 or 4 steps )
using AUTOIT...then right click the .au3 file you have to compile ....after that you will
get the .exe file with the name of .au3 file ..In eclipse you will give the code like this
<----ProcessBuildder ps = new ProcessBuilder("path of the .exe file of au3") .start();--->
Q #69) How to handle internationalisation through web driver?
FirefoxProfile profile = new FirefoxProfile();
[Link] Preference("intl.accept_languages","jp");
Web driver driver = new FirefoxDriver(profile); [Link]([Link]) will open google in
Japanese Lang
Q #70) How to overcome same origin policy through web driver?
· Proxy server.
DesiredCapabilities capability=new [Link]();
[Link]([Link],"your desire proxy")
WebDriver driver=new FirefoxDriver(capability);
Q #71) How to put text in Facebook search box using
selenium web driver.
· [Link]([Link]("//div[contains(@class, '_586i')]")).sendKeys("abc");
Q #72) Difference between flex and flash application.
In flash there is no code just based on creativity(design) we will complete the
work(time consuming process) whereas flex contain some small functions
which is integrated with mxml,PHP..(no tool is there to develop
flex we want to use the properties of css and style sheet)
Q #73) What is Error Collector in TestNG? What is its use?
This class allows the collection of errors during the process of retrieving the
test data for the test method parameters
Q #74) How can we get the font size, font color, font type used for a particular text on a web
page using Selenium web driver?
[Link]([Link]("Xpath ").getcssvalue("font-size);
[Link]([Link]("Xpath ").getcssvalue("font-colour);
[Link]([Link]("Xpath ").getcssvalue("font-type);
[Link]([Link]("Xpath ").getcssvalue("background-colour);
Q #75) How to run tests in multiple browser parallel?Is there any other option other than selenium
grid?
You create a class with a method something like this:
public class LaunchBrowser {
Selenium Notes Page 18
WebDriver driver=null;
// Pass parameter browser from [Link]
@Parameters(“browser”)
public void initiateBrowser(String browser){
// compare browser to fire fox and then open firefox driver
if([Link](“Firefox”))
{
driver = new FirefoxDriver();
}
else
{
\ set path to the IE driver correctly here
[Link]("[Link]", "\[Link]");
driver =new InternetExplorerDriver();
}
}
Now create YourClassName class and call extend the above class something like this
@Test
public class YourClassName extends LaunchBrowser{
public void gotoGoogle(){
[Link](“[Link]
}
}
Q #76) How to prepare Customized html Report using TestNG in hybrid framework.
Below are the 3 ways:
• Junit: with the help of ANT.
• TestNG: using inbuilt [Link] to get the HTML report. Also XST reports from ANT,
Selenium, TestNG combination.
• Using our own customized reports using XSL jar for converting XML content to HTML.
Q #77) “What’s the hierarchy of TestNG annotations?Explain me about annotation hierarchy &
executionorder?
1. [Link] (implements [Link])
2. [Link] (implements [Link])
3. [Link] (implements [Link])
4. [Link] (implements [Link])
5. [Link] (implements [Link])
Selenium Notes Page 19
6. [Link] (implements [Link])
7. [Link] (implements [Link])
8. [Link] (implements [Link])
9. [Link] (implements [Link])
10. [Link] (implements [Link])
11. [Link] (implements [Link])
12. [Link] (implements [Link])
13. [Link] (implements [Link])
14. [Link] (implements [Link])
15. [Link] (implements [Link])
16. [Link] (implements [Link])
17. [Link] (implements [Link])
18. [Link] (implements [Link])
19. [Link] (implements [Link])
20. [Link] (implements [Link])
21. [Link] (implements [Link])
22. [Link] (implements [Link])
Q #78) How the TestNG interacts with Selenium Core?Explain me steps and internal architecture?"
What is TestNG?
So far we had been doing Selenium tests without generating a proper format for the test results.
From this point on, we shall tackle how to make these reports using a test framework called TestNG.
TestNG is a testing framework that overcomes the limitations of another popular testing framework
called JUnit. The "NG" means "Next Generation". Most Selenium users use this more than JUnit
because of its advantages. There are so many features of TestNG, but we will only focus on the most
important ones that we can use in [Link] of TestNG over JUnit
There are three major advantages of TestNG over JUnit:
Annotations are easier to understand
Test cases can be grouped more easily
Parallel testing is possible
Q #79) Is it possible test web services using selenium?
Using Jmeter we can test how one website is talking to each other means time taken to
send data, feeds, messages from one website to other website. Jmeter does a nice job
of doubling for performance and api tests.
Q #80) How to refresh a page without using context click?
[Link] [Link] method
[Link] [Link]() method
Selenium Notes Page 20
[Link] [Link]() method
[Link] get() method
[Link] sendKeys() method
[Link] [Link] method
[Link]("[Link]
[Link]([Link]("firstname-placeholder")).sendKeys(Keys.F5);
[Link] [Link]() method
[Link]("[Link]
[Link]");
[Link]().refresh();
[Link] [Link]() method
[Link]("[Link]
[Link]");
[Link]().to([Link]());
[Link] get() method
[Link]("[Link]
[Link]");
[Link]([Link]());
[Link] sendKeys() method
[Link]("[Link]
[Link]([Link]("firstname-placeholder")).sendKeys("\uE035");
Q #81) Can u send a code for printing in selenium?
There are two cases:
Case1. Any hyperlink/button on a web page, n clicking that link/button a print dialog box
opens. (Performing an action on web page)
[Link] do u want to open print dialog box within ur own script, not by performing any
action on web page.
So If Case 1: just a call for [Link]() event will work to open it.
If Case 2: Call a Printer Job object (Use Awt API).
For code: Google it.
Q #82) How to find broken images in a page using Selenium Web driver.
1. Get xpath and then using tag name; get all the links in the page
2. Click on each and every link in the page
3. In the target page title, look for 404/500 error.
How to find broken images in a page using Selenium
package programs;
import [Link];
Selenium Notes Page 21
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class findbrokenimages {
static int invalidimg;
static WebDriver driver ;
public static void main(String[] args) {
try {
driver = new FirefoxDriver();
[Link]("[Link]
invalidimg = 0;
List allImages = [Link]([Link]("img"));
[Link]("Total images are " + [Link]());
for (int i = 0; i < [Link](); i++) {
WebElement img = (WebElement) [Link](i);
if (img != null) {
verifyimgActive(img);
}
}
[Link]("Total invalid images are " + invalidimg);
[Link]();
} catch (Exception e) {
[Link]();
[Link]([Link]());
}
}
public static void verifyimgActive(WebElement img) {
try {
HttpResponse response = new DefaultHttpClient().execute(new HttpGet([Link]("src")));
if ([Link]().getStatusCode() != 200)
invalidimg++;
}
Selenium Notes Page 22
catch (Exception e) {
[Link]();
}
}
}
Q #83) How to handle Ajax popup window?
By using getWindowHandles() and [Link](windowid) we can handle popups using
explicit wait and [Link]("name") commands for your requirements.
Q #84) How to handle auto complete box in web driver?
How to handle autocomplete box in web driver
How to handle autocomplete box in web driver?
[Link]([Link]("your searchBox")).sendKeys("your partial keyword");
[Link](3000);
List <WebElement> listItems = [Link]([Link]("your list item locator"));
[Link](0).click();
[Link]([Link]("your searchButton")).click();
Q #85) How to get the name of browser using Web Driver?
public class JsExecute
{
WebDriver driver;
JavascriptExecutor js;
@Before
public void setUp() throws Exception
{
driver=new FirefoxDriver();
[Link]("[Link]
}
@Test
public void test()
{
JavascriptExecutor js = (JavascriptExecutor) driver;
[Link]([Link]("return [Link]"));
}}
OR
String s = (String) ((JavascriptExecutor) driver).executeScript("return [Link];");
[Link]("Browser name : " + s);
Q #86) How to handle colors in web driver?
Use getCssValue(arg0) function to get the colors by sending 'color' string as an argument.
Selenium Notes Page 23
Example
String col = [Link]([Link](locator)).getCssValue("color");
Q #87) How to pass parameters from [Link] into test case.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Parallelexecution {
private WebDriver driver = null;
@BeforeTest
@Parameters({ "BROWSER" })
public void setup(String BROWSER) {
[Link]("Browser: " + BROWSER);
if ([Link]("FF")) {
[Link]("Firefox Browser is selected");
driver = new FirefoxDriver();
} else if ([Link]("IE")) {
[Link]("Internet Explorer Browser is selected");
driver = new InternetExplorerDriver();
} else if ([Link]("HU")) {
[Link]("Html Unit Browser is selected");
driver = new HtmlUnitDriver();
} else if ([Link]("CH")) {
[Link]("Google chrome Browser is selected");
driver = new ChromeDriver();
}
}
@Test
public void testParallel() throws Exception {
Selenium Notes Page 24
[Link]("[Link]
[Link]");
}
}
Q #88) How to get text from captcha image??
[Link]([Link](".//*[@id='SkipCaptcha']")).click();
String attr = [Link]([Link](".//*[@id='SkipCaptcha']")).getAttribute("value");
[Link]("The value of the attribute 'Name' is " + attr);
Q #89) Is there a way to click hidden LINK in web driver?
String Block1 = [Link]([Link]("element ID"));
JavascriptExecutor js1=(JavascriptExecutor)driver;
[Link]("$("+Block1+").css({'display':'block'});");
Q #90) What Class Extends Web Driver?
· AndroidDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver,
InternetExplorerDriver, IPhoneDriver, PhantomJSDriver, RemoteWebDriver, SafariDriver
Q #91) What are the APIs that support Web Driver?
· API are nothing but collection of all selenium commands for Locating UI Elements
(WebElements),Fetching a Page,User Input etc…
Q #92) How to disable cookies in browser.
· Using deleteAllVisibleCookies() in selenium
Q #93) "We have heard about frameworks well it can be broadly classified into these TDD, BDD
and ATDD frameworks .What’s the Difference?"
TDD- Test Driven Development, Behaviour Driven Development & Acceptance TestDriven
Development
Well, you could see the above Acronyms buzzing over all Automation folks. I was not sure on what it
means and How it differs each other. How each methodology will benefit? and where exactly it will
help in the Development Life cycle.
Finally, after some analysis I had found out the differences and posting it here. Readers are always
welcomed to correct me if I am wrong.
First lets list out what exactly each methodology does means
TDD – Test Driven Development
Its also called test-driven design, is a method of software development in which unit testing is
repeatedly done on source code. Write your tests watch it fails and then refactor it. The concept is
we write these tests to check if the code we wrote works fine. After each test, refactoring is done
and then the same or a similar test is performed again. The process is iterated as many times as
Selenium Notes Page 25
necessary until each unit is functionally working as expected. TDD was introduced first by XP. I
believe I have explained enough in simple terms.
BDD – Behaviour Driven Development
Behavior-driven development combines the general techniques and principles of TDD with ideas
from domain-driven design
DDD-Domain Driven Testing
BDD is similar in many ways to TDD except that the word “test” is replaced with the word
“Behaviour”. It’s purpose is to help the the folks devising the system (i.e., the developer) identify
appropriate tests to write–that is, tests that reflect the behavior desired by the stakeholders. BDD is
usually done in very English-like language helps the Domain experts to understand the
implementation rather than exposing the code level tests. Its defined in a GWT format, GIVEN WHEN
& THEN.
Q #94) How to change user agent in Firefox by selenium web driver.
FirefoxProfile profile = new FirefoxProfile();
[Link]("[Link]", "some UA string");
Web Driver driver = new FirefoxDriver(profile);
Q #95) What is Selenese?
Selenese is HTML language based command, which is used in Selenium IDE.
Q #96) Differences between QTP and selenium.
1) Selenium generates a proxy while starting browser. QTP does not
2) QTP uses only Vb script. Selenium is available in many languages
3) QTP is paid and selenium is free.
4) You can run script from a particular line in QTP but in selenium, you cannot.
5) Selenium works on all browsers. QTP only works on IE, mozilla. Support from chrome has been
introduced lately.
6) QTP is more organized and user friendly
7) Selenium requires more technical skills
8) QTP can also be used on desktop based applications but selenium cannot be used
Q #97) What is the MOST challenging test problem in my career in Automation?
In my career
· Changing XPATHS' between testing server and production server-by keeping generic xpath
· Keep separate property files for production and UAT
· automating flash apps
· Mobile Automation
Q #98) “Suppose developer changed the existing image to new image with same xpath. Is test case
pass or fail?"
· Pass
Selenium Notes Page 26
Q #99) How to handle network latency using selenium?
· Using [Link] for network latency
Q #100) How does u handle dynamic elements without using xpath (with example?)
· By using classname or css.
Q #101)What are the different types of driver implementation?
· AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver,
HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver,
RemoteWebDriver, SafariDriver, WebDriverBackedSelenium
Q #102)Code for Opening Firefox browser?
· Webdriver driver=new FireFoxdriver();
Q #103)Which repository you have used to store the test
scripts?
I have created scripts in excel file and store them in Test cases folder under src .
Q #104)How to work with radio button in web driver?
We can select the value from the drop down by using 3 methods.
selectByVisibleText - select by the text displayed in drop down
selectByIndex - select by index of option in drop down
selectByValue - select by value of option in drop down
<select id="44"> <option value="1">xyz</option>
<option value="2">abc</option>
<option value="3">pqr</option>
</select>
WebElement e = [Link]([Link]("44"));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
[Link]("xyz");
[Link]("1");
55. How to work with dynamic web table?
You can get the total number of <tr> tags within a <td> tag by giving the xpath of the
<td> element by using this function -
List<WebElement> ele = [Link]([Link]("Xpath of the table"));
Now you can use a for each loop to loop through each of the <tr> tags in the above list
and then read each value by using getText() method.
56. Detail about TestNG Test Output folder.
It is the directory where reports are generated. Every time tests run in a suite, TestNG
creates [Link] and other files in the output directory.
Q #105)In frame if no frame Id as well as no frame name then which attribute I should consider
throughout our script.
Selenium Notes Page 27
You can go like this.....[Link]([Link]("//iframe"))...
Then it will return List of frames then switch to each and every frame and search for
the locator which you want then break the loop
Q #106)What is object repository?
It is collection of object names their properties, attributes and their values .It maye be
excel, XML,property file or text file
Q #107) TestNG vs. Junit?
Advantages of TestNG over Junit
In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG
there is no constraint like this.
Additional Levels of setUp/tearDown level are available in TestNG like
@Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
No Need to extend any class in TestNG.
There is no method name constraint in TestNG as in Junit. You can give any name to the test
methods in TestNG
In TestNG we can tell the test that one method is dependent on another method where as in Junit
this is not possible. In Junit each test is independent of another test.
Grouping of testcases is available in TestNG where as the same is not available in Junit.
Execution can be done based on Groups. For ex. If you have defined many cases and segregated
them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity”
cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases
belonging to the “Sanity” group.
Also using TestNG your selenium test case execution can be done in parallel.
Q #108) What is the difference between @before?
method and @beforeclass.
In JUnit4 @Before is used to execute set of preconditions before executing a test.
For example, if there is a need to open some application and create a user before
executing a test, then this annotation can be used for that method. Method that is
marked with @Before will be executed before executing every test in the class.
If a JUnit test case class contains lot of tests which all together need a method
which sets up a precondition and that needs to be executed before executing the
Test Case class then we can utilise “@BeforeClass” annotation.
Q #109) What are the different Parameters for @Test annotation?
Parameters are keywords that modify the annotation’s function.
Q #110) Can we run group of test cases using TestNG?
Test cases in group in Selenium using TestNG will be executed with the below options.
If you want to execute the test cases based on one of the group like regression test or smoke test
@Test(groups = {"regressiontest", "smoketest"})
Selenium Notes Page 28
Q #111) Differences between Selenium web driver,
IDE and RC?
Q #112) How to highlight an object like qtp/uft does through selenium and java?
public void highlightElement(WebDriver driver, WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
[Link]("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border:
2px solid yellow;");
[Link]("arguments[0].setAttribute('style', arguments[1]);", element, "");
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight
as arguments.
Q #113) What are the different assertions in SIDE?
Assertions are like Accessors, but they verify that the state of the application conforms to what is
expected. Examples include "make sure the page title is X" and "verify that this checkbox is
checked".
All Selenium Assertions can be used in 3 modes: "assert", "verify", and "waitFor".
For example, you can "assertText", "verifyText" and "waitForText". When an "assert" fails, the test is
aborted. When a "verify" fails, the test will continue execution, logging the failure. This allows a
single "assert" to ensure that the application is on the correct page, followed by a bunch of "verify"
assertions to test form field values, labels, etc.
"waitFor" commands wait for some condition to become true (which can be useful for testing Ajax
applications). They will succeed immediately if the condition is already true. However, they will fail
and halt the test if the condition does not become true within the current timeout setting (see
thesetTimeout action below).
Q #114) How to store a value which is text box using web driver?
[Link]([Link]("your Textbox")).sendKeys("your keyword");
Q #115) How to handle alerts and confirmation boxes.
Confirmation boxes and Alerts are handled in same way in selenium.
var alert = [Link]().alert();
[Link](); //Click Cancel or Close window operation
[Link](); //Click OK
Handle Confirmation boxes via JavaScript,
[Link]("[Link] = function(message){return true;};");
Selenium Notes Page 29
Q #116) How to mouse hover on an element?
Actions action = new Actions(webdriver);
WebElement we = [Link]([Link]("html/body/div[13]/ul/li[4]/a"));
[Link](we).moveToElement([Link]([Link]("/expression-
here"))).click().build().perform();
Q #117) How to switch between the windows?
private void handlingMultipleWindows(String windowTitle) {
Set<String> windows = [Link]();
for (String window : windows) {
[Link]().window(window);
if ([Link]().contains(windowTitle)) { return; } } }
Q #118) How to switch between frames?
WebDriver's [Link]().frame() method takes one of the three possible arguments:
A number.
Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be
at index "0", the second at index "1" and the third at index "2". Once the frame has been selected,
all subsequent calls on the WebDriver interface are made to that frame.
A name or ID.
Select a frame by its name or ID. Frames located by matching name attributes are always given
precedence over those matched by ID.
A previously found WebElement.
Select a frame using its previously located WebElement.
Get the frame by it's id/name or locate it by [Link]() and you'll be good.
Q #119) What is actions class in web driver?
Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop,
hovering a mouse, especially in a case when dealing with mouse over menus.
Dragging & Dropping an Element:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class testDragandDrop {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
[Link]("[Link]
WebElement draggable = [Link]([Link]("//*[@id='draggable']"));
WebElement droppable = [Link]([Link]("//*[@id='droppable']"));
Selenium Notes Page 30
Actions action = new Actions(driver);
[Link](draggable, droppable).perform();
}
}
Sliding an Element:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class testSlider {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
[Link]("[Link]
WebElement slider = [Link]([Link]("//*[@id='slider']/a"));
Actions action = new Actions(driver);
[Link](3000);
[Link](slider, 90, 0).perform();
}
}
Re-sizing an Element:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class testResizable {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
[Link]("[Link]
WebElement resize = [Link]([Link]("//*[@id='resizable']/div[3]"));
Actions action = new Actions(driver);
[Link](resize, 400, 200).perform();
}
Selenium Notes Page 31
}
Q #120) Difference between the selenium1.0 and selenium 2.0?
Selenium 1 = Selenium Remote Control.
Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and Web driver.
73. Difference between find element () and
findelements ()?
findElement() :
Find the first element within the current page using the given "locating mechanism".
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given "locating mechanism".
Returns List of Web Elements.
Q #121) How to take the screen shots in seelnium2.0?
// store screenshots
public static void captureScreenShot(String filePath) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs([Link]);
try {
[Link](scrFile, new File(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
[Link]();
}
}
Q #122) What is the default time for selenium Ide and webdriver?
Default timeout in selenium ide is 30 seconds.
Q #123) Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.
Q #124) In TestNG I have some test's Test1-Test2- Test3-Test4-Test5I want to run my execution
order is [Link] do you set the execution order can you explain
for that?
· Use priority parameter in @test annotation or TestNG annotations.
Q #125) Differences between jxl and ApachePOI.
· jxl does not support XLSX files
· jxl exerts less load on memory as compared to ApachePOI
· jxl doesn't support rich text formatting while ApachePOI does.
· jxl has not been maintained properly while ApachePOI is more up to date.
· Sample code on Apache POI is easily available as compare to jxl.
Selenium Notes Page 32
Q #126) How to ZIP files in Selenium with an Example?
// Sample Function to make zip of reports
public static void zip(String filepath){
try
{
File inputFolder=new File('Mention file path her");
File outputFolder=new File("[Link]");
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = [Link]();
for (int j=0; j<[Link]; i++)
{
in = new BufferedInputStream(new FileInputStream
([Link]() + "/" + files[j]), 1000);
[Link](new ZipEntry(files[j]));
int totalcount;
while((totalcount= [Link](data,0,1000)) != -1)
{
[Link](data, 0, totalcount);
}
[Link]();
}
[Link]();
[Link]();
}
catch(Exception e)
{
[Link]();
return "Fail - " + [Link]();
}
}
Q #127) What is default port no?
4444
Selenium Notes Page 33
Q #128) If Default port no is busy how to change port no?
We can use any port number which is valid.. First create an object to remote control configuration.
Use 'setPort' method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
[Link](4567);
SeleniumServer s= new SeleniumServer(r);
Q #129) Does Selenium support https protocols?
Yes
Q #130) Majorly asked test scenario with framework in Interviews?
Majorly asked are:
· Login for Gmail scenario
· Goggle search and finding no of results
· Downloading a file and save it
· Checking mails and deleting them
· Do shopping in [Link]
Q #131) Selenium support mobile applications?
No, it is browser automation tool, it only automates Websites opening in mobile browser, and
mobile APPs
can't be automated.
Q #132) What is wraps Driver?
For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
Q #133) Can you explain Junit Annotation? If there are 1000 test cases. 500 test cases are
executed. How will you execute the rest of the test cases by using annotation?"
The annotations generated with JUnit 4 tests in Selenium are:
1. @Before public void method() - Will perform the method() before each test. This method
can prepare the test
2. @Test public void method() - Annotation @Test identifies that this method is a test
[Link],e.g. read input data, initialize the class)
3. @After public void method() - Test method must start with test@Before - this annotation
is used for executing a method before
Q #134) Difference between assert and verify in selenium web driver.
· When an “assert” fails, the test will be aborted. Assert is best used when the
check value has to pass for the test to be able to continue to run log in.
· Where if a “verify” fails, the test will continue executing and logging the failure.
Verify is best used to check non critical things. Like the presence of a
headline element.
Selenium Notes Page 34
Q #135) "I want to find the location of ""b"" in the below code, how can I find out without using
xpath, name,id, csslocator, index.<div>
<Button>a</button>
<Button>b</button>
<Button>c</button>
</div>
[Link]([Link]("//*[contains(text(),'b')]")).click(); or
//div/button[contains(text(),'b']
Q #136) How to do Applet testing using selenium?
// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
[Link]();
[Link](url);
// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = [Link](LIST_APPLET_ID)
// fest similar API for autmation testing
[Link]("domain").select("Users");
[Link]("username").enterText("[Link]");
[Link]("ok").click();
Q #137) Name 5 different exceptions you had in selenium web driver and mention what instance
you got it and how do you resolve it?
· WebDriverException
· NoAlertPresentException
· NoSuchWindowException
· NoSuchElementException
· TimeoutException
Q #138) How do you manage the code versions in your project?
· Using SVN or other versioning tools
Q #139) Latest version of Firefox and selenium in market and the version on which you are testing
which you are testing.
· FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
· Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at
Q #140) How to know all the methods supported in web driver and its syntax.
· In [Link] package, web driver interface has all the main methods that can
be used in Selenium Web driver
Q #141) How do you create html test report from your test script?
• I would see below 3 ways:
• Junit: with the help of ANT.
• TestNG: using inbuilt [Link] to get the HTML report. Also XLST reports from ANT,
Selenium Notes Page 35
Selenium, TestNG combination.
• Using our own customized reports using XSL jar for converting XML content to HTML.
Q #142) List the browsers, OS supported by the SeleniumWindows Linux Mac?
IE Y NA NA
FF Y Y Y
Safari Y N Y
Opera Y Y Y
Chrome Y Y Y
Q #143) Can you explain Selenium Mobile Automation?
import junit . framework . TestCase ;
import [Link];
import [Link];
import [Link];
public class OneTest extends TestCase {
public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();
// And now use this to visit Google
[Link]("[Link]
// Find the text input element by its name
WebElement element = [Link]([Link]("q"));
// Enter something to search for
[Link]("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
[Link]();
// Check the title of the page
[Link]("Page title is: " + [Link]());
[Link]();
}
}
Q #144) What mobile devices it may Support?
Selenium Web driver supports all the mobile devices operating on Android, IOS operating Systems
· Android – for phones and tablets (devices & emulators)
· iOS for phones (devices & emulators) and for tablets (devices & emulators)
Q #145) What is the difference between single and double slash in Xpath?
/
[Link] starts selection from the document node
2. It Allows you to create 'absolute' path expressions
Selenium Notes Page 36
3. e.g “/html/body/p” matches all the paragraph elements
//
1. It starts selection matching anywhere in the document
2. It Allows you to create 'relative' path expressions
3. e.g“//p” matches all the paragraph elements
Q #146) What are the test types supported by Selenium?
Selenium supports UI and functional testing. As well it can support performance testing
for reasonable load using selenium grid.
Q #147) In what all case we have to go for “JavaScript executor”.
Consider FB main page after you login. When u scrolls down, the updates get loaded. To
handle this activity, there is no selenium command. So you can go for javascript to set
the scroll down value like [Link]("[Link](0,200)", "");
Q #148) How will you find an element using Selenium?
In Selenium every object or control in a web page is referred as an elements, there are different
ways to find an element in a web page they are
ID
Name
Tag
Attribute
CSS
Linktext
PartialLink Text
Xpath etc
Q #149) List out the test types that are supported by Selenium?
For web based application testing selenium can be used
The test types can be supported are
a) Functional
b) Regression
For post release validation with continuous integration automation tool could be used
a) Jenkins
b) Hudson
c) Quick Build
d) CruiseCont
Q #150) Explain what is assertion in Selenium and what are the types of assertion?
Assertion is used as a verification point. It verifies that the state of the application conforms to what
is expected. The types of assertion are “assert” , “verify” and “waifFor”.
Selenium Notes Page 37
Q #151) Mention what is the use of X-path?
X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic
elements.
7) Explain the difference between single and double slash in X-path?
Single slash ‘/ ’
Single slash ( / ) start selection from the document node
It allows you to create ‘absolute’ path expressions
Double Slash ‘// ’
Double slash ( // ) start selection matching anywhere in the document
It enables to create ‘relative’ path expressions
Q #152) List out the technical challenges with Selenium?
Technical challenges with Selenium are
Selenium supports only web based applications
It does not support the Bitmap comparison
For any reporting related capabilities have to depend on third party tools
No vendor support for tool compared to commercial tools like HP UFT
As there is no object repository concept in Selenium, maintainability of objects becomes
difficult
Q #153) What is the difference between type keys and type commands ?
TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t. Type key
populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing
10) What is the difference between verify and assert commands?
Assert: Assert allows to check whether an element is on the page or not. The test will stop on the
step failed, if the asserted element is not available. In other words, the test will terminated at the
point where check fails.
Verify: Verify command will check whether the element is on the page, if it is not then the test will
carry on executing. In verification, all the commands are going to run guaranteed even if any of test
fails.
11) What is JUnit Annotations and what are different types of annotations which are useful ?
Selenium Notes Page 38
In JAVA a special form of syntactic meta-data can be added to Java source code, this is know as
Annotations. Variables, parameters, packages, methods and classes are annotated some of the JUnit
annotations which can be useful are
Test
Before
After
Ignore
BeforeClass
AfterClass
RunWith
12) While using click command can you use screen coordinate?
To click on specific part of element, you would need to use clickAT command. ClickAt command
accepts element locator and x, y co-ordinates as arguments-
clickAt (locator, cordString)
Q #154) What are the advantages of Selenium?
It supports C#, PHP, Java, Perl, Phython
It supports different OS like Windows, Linux and Mac OS
It has got powerful methods to locate elements (Xpath, DOM , CSS)
It has highly developer community supported by Google
Q #155) Why testers should opt for Selenium and not QTP?
Selenium is more popular than QTP as
Selenium is an open source whereas QTP is a commercial tool
Selenium is used specially for testing web based applications while QTP can be used for
testing client server application also
Selenium supports Firefox, IE, Opera, Safari on operating systems like Windows, Mac, linux
etc. however QTP is limited to Internet Explorer on Windows.
Selenium supports many programming languages like Ruby, Perl, Python whereas QTP
supports only VB script
Q #156) What are the four parameter you have to pass in Selenium?
Four parameters that you have to pass in Selenium are
Host
Port Number
Browser
URL
Q #157) What is the difference between setSpeed() and sleep() methods?
Both will delay the speed of execution.
Selenium Notes Page 39
[Link] () : It will stop the current (java) thread for the specified period of time. Its done only
once
It takes a single argument in integer format
Ex: [Link](2000)- It will wait for 2 seconds
It waits only once at the command given at sleep
SetSpeed () : For specific amount of time it will stop the execution for every selenium command.
• It takes a single argument in integer format
Ex: [Link](“2000”)- It will wait for 2 seconds
• Runs each command after setSpeed delay by the number of milliseconds mentioned in set
Speed
This command is useful for demonstration purpose or if you are using a slow web application
Q #158) What is same origin policy? How you can avoid same origin policy?
The “Same Origin Policy” is introduced for security reason, and it ensures that content of your site
will never be accessible by a script from another site. As per the policy, any code loaded within the
browser can only operate within that website’s domain.
To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium
Server acts as a client configured HTTP proxy , which sits between the browser and application under
test and then masks the AUT under a fictional URL
Q #159) What is heightened privileges browsers?
The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something
that are not commonly permitted. The key difference is that the browsers are launced in a special
mode called heightened privileges. By using these browser mode, Selenium core can open the AUT
directly and also read/write its content without passing the whole AUT through the Selenium RC
server.
Q #160) How you can use “submit” a form using Selenium ?
You can use “submit” method on element to submit form-
[Link] () ;
Alternatively you can use click method on the element which does form submission
Q #161) What are the features of TestNG and list some of the functionality in TestNG which makes
it more effective?
TestNG is a testing framework based on JUnit and NUnit to simplify a broad range of testing needs,
from unit testing to integration testing. And the functionality which makes it efficient testing
framework are
• Support for annotations
• Support for data-driven testing
• Flexible test configuration
Selenium Notes Page 40
• Ability to re-execute failed test cases
Q #162) Mention what is the difference between Implicit wait and Explicit wait?
Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of
time it will try looking for element again and again before throwing a NoSuchElementException. It
waits for elements to show up.
Explicit Wait : It is a one-timer, used for a particular search.
Q #163) Which attribute you should consider throughout the script in frame for “if no frame Id as
well as no frame name”?
You can use…..[Link]([Link](“//iframe”))….
This will return list of frames.
You will ned to switch to each and every frame and search for locator which we want.
Then break the loop
Q #164) Explain what is the difference between find elements () and find element () ?
find element ():
It finds the first element within the current page using the given “locating mechanism”. It returns a
single WebElement
findElements () : Using the given “locating mechanism” find all the elements within the current page.
It returns a list of web elements.
Q #165) Explain what are the JUnits annotation linked with Selenium?
The JUnits annotation linked with Selenium are
• @Before public void method() – It will perform the method () before each test, this method
can prepare the test
• @Test public void method() – Annotations @Test identifies that this method is a test
method environment
• @After public void method()- To execute a method before this annotation is used, test
method must start with test@Before
Q #166) Explain what is Datadriven framework and Keyword driven?
Datadriven framework: In this framework, the test data is separated and kept outside the Test
Scripts, while test case logic resides in Test Scripts. Test data is read from the external files ( Excel
Files) and are loaded into the variables inside the Test Script. Variables are used for both for input
values and for verification values.
Keyworddriven framework: The keyword driven frameworks requires the development of data
tables and keywords, independent of the test automation. In a keyword driven test, the
functionality of the application under test is documented in a table as well as step by step
instructions for each test.
Q #167) Explain how you can login into any site if it’s showing any authentication popup for
password and username?
Selenium Notes Page 41
Pass the username and password with url
• Syntax-[Link]
• ex- [Link]
Q #168) Explain how to assert text of webpage using selenium 2.0 ?
WebElement el = [Link]([Link](“ElementID”))
//get test from element and stored in text variable
String text = [Link]();
//assert text from expected
[Link](“Element Text”, text);
Q #169) Explain what is the difference between Borland Silk and Selenium?
Silk Test Tool Selenium Test Tool
Borland Silk test is not a free testing tool Selenium is completely free test automation tool
Selenium supports many browsers like Internet
Silk test supports only Internet Explorer and Firefox Explorer, Firefox, Safari, Opera and so on
Selenium suite has the flexibility to use many
Silk test uses test scripting language languages like Java, Ruby,Perl and so on
Silk test can be used for client server applications Selenium can be used for only web application
Q #170) What is Object Repository ?
An object repository is an essential entity in any UI automations which allows a tester to store all
object that will be used in the scripts in one or more centralized locations rather than scattered all
over the test scripts.
Q #171) Explain how Selenium Grid works?
Selenium Grid sent the tests to the hub. These tests are redirected to Selenium Webdriver, which
launch the browser and run the test. With entire test suite, it allows for running tests in parallel.
Q #172) Can we use Selenium grid for performance testing?
Yes. But not as effectively as a dedicated performance testing tool like Loadrunner.
Webdriver (Selenium ) Interview Questions and answers
Q #173) What is Selenium 2.0
Answer: Webdriver is open source automation tool for web application. WebDriver is designed to
provide a simpler, more concise programming interface in addition to addressing some limitations in
Selenium Notes Page 42
the Selenium-RC API.
Q #174) What is cost of webdriver, is this commercial or open source.
Answer: selenium is open source and free of cost.
Q #175) how you specify browser configurations with Selenium 2.0?
Answer: Following driver classes are used for browser configuration
AndroidDriver,
ChromeDriver,
EventFiringWebDriver,
FirefoxDriver,
HtmlUnitDriver,
InternetExplorerDriver,
IPhoneDriver,
IPhoneSimulatorDriver,
RemoteWebDriver
Q #176) How is Selenium 2.0 configuration different than Selenium 1.0?
Answer: In case of Selenium 1.0 you need Selenium jar file pertaining to one library for example in
case of java you need java client driver and also Selenium server jar file. While with Selenium 2.0 you
need language binding (i.e. java, C# etc) and Selenium server jar if you are using Remote Control or
Remote WebDriver.
Q #177) Can you show me one code example of setting Selenium 2.0?
Answer: below is example
WebDriver driver = new FirefoxDriver();
[Link]("[Link]
[Link]([Link]("#gb_2 > [Link]")).click();
[Link]([Link]("#gb_1 > [Link]")).click();
[Link]([Link]("#gb_8 > [Link]")).click();
[Link]([Link]("#gb_1 > [Link]")).click();
Q #178) Which web driver implementation is fastest?
Answer: HTMLUnitDriver. Simple reason is HTMLUnitDriver does not execute tests on browser but
plain http request – response which is far quick than launching a browser and executing tests. But
then you may like to execute tests on a real browser than something running behind the scenes
Q #179) What all different element locators are available with Selenium 2.0?
Answer: Selenium 2.0 uses same set of locators which are used by Selenium 1.0 – id, name, css,
XPath but how Selenium 2.0 accesses them is different. In case of Selenium 1.0 you don’t have to
specify a different method for each locator while in case of Selenium 2.0 there is a different method
available to use a different element locator. Selenium 2.0 uses following method to access elements
with id, name, css and XPath locator –
[Link]([Link]("HTMLid"));
[Link]([Link]("HTMLname"));
[Link]([Link]("cssLocator"));
[Link](By. className ("CalssName”));
[Link](By. linkText ("LinkeText”));
[Link](By. partialLinkText ("PartialLink”));
[Link](By. tagName ("TanName”));
Selenium Notes Page 43
[Link]([Link]("XPathLocator));
Q #180) How do I submit a form using Selenium?
Answer:
WebElement el = [Link]([Link]("ElementID"));
[Link]();
Q #181) How to capture screen shot in Webdriver?
Answer:
File file= ((TakesScreenshot)driver).getScreenshotAs([Link]);
[Link](file, new File("c:\\[Link]"));
Q #182) How do I clear content of a text box in Selenium 2.0?
Answer:
WebElement el = [Link]([Link]("ElementID"));
[Link]();
Q #183) How to execute java scripts function.
Answer:
JavascriptExecutor js = (JavascriptExecutor) driver;
String title = (String) [Link]("pass your java scripts");
Q #184) How to select a drop down value using Selenium2.0?
Answer: See point 16 in below post:
Click here for answer
Q #185) How to automate radio button in Selenium 2.0?
Answer:
WebElement el = [Link]([Link]("Radio button id"));
//to perform check operation
[Link]()
//verfiy to radio button is check it return true if selected else false
[Link]()
Q #186) How to capture element image using Selenium 2.0?
Answer: click link for answer:
Q #187) How to count total number of rows of a table using Selenium 2.0?
List {WebElement} rows = [Link]([Link]("//table[@id='tableID']/tr"));
int totalRow = [Link]();
Q #188) How to capture page title using Selenium 2.0?
String title = [Link]()
Q #189) How to store page source using Selenium 2.0?
String pagesource = [Link]()
Q #190) How to store current url using selenium 2.0?
String currentURL = [Link]()
Selenium Notes Page 44
Q #191) How to assert text assert text of webpage using selenium 2.0?
WebElement el = [Link]([Link]("ElementID"));
//get test from element and stored in text variable
String text = [Link]();
//assert text from expected
[Link]("Element Text", text);
Q #192) How to get element attribute using Selenium 2.0?
WebElement el = [Link]([Link]("ElementID"));
//get test from element and stored in text variable
String attributeValue = el. getAttribute("AttributeName") ;
Q #193) How to double click on element using selenium 2.0?
WebElement el = [Link]([Link]("ElementID"));
Actions builder = new Actions(driver);
[Link](el).build().perform();
Q #194) How to perform drag and drop in selenium 2.0?
WebElement source = [Link]([Link]("Source ElementID"));
WebElement destination = [Link]([Link]("Taget ElementID"));
Actions builder = new Actions(driver);
[Link](source, destination ).perform();
Q #195) How to maximize window using selenium 2.0?
[Link]().window().maximize();
Q #196) What Is Selenium WebDriver/Selenium 2?
Selenium WebDriver Is well designed object oriented API which Is developed to automate
web and mobile applications testing process. WebDriver API Is bigger than Selenium RC but It's
Architecture Is simple and easy to understand compared Selenium RC API.
We can automate our web application testing process using selenium webdriver.
We can say It advanced version of selenium RC because some limitations of selenium RC has
been overcome In selenium WebDriver.
WebDriver Is designed to provide better support for dynamic changing
pages. Example : Web page elements changing without reloading the page. In this case WebDriver
works better.
Selenium Webdriver Is more faster that Selenium RC as It Is directly Interacting with web
browsers and mimic the behavior of a real user. Example : User clicks on button of web page or
moving mouse on main menu to get the sub menu list. WebDriver works Same.
All popular browser vendors are active participants In selenium WebDriver's development
and all of them have their own engineers team to Improve this framework.
You can Include answers of Question 2, Question 3, Question 4 and Question 5 In answer of this
question If Interviewer need more detail on selenium webdriver.
Q #197) Tell Me WebDriver Supported Browsers?
Selenium Notes Page 45
Answer : Selenium WebDriver API has a many different drivers to test your web application In
different browsers. List of Webdriver browser drivers are as bellow.
Firefox Driver - For Mozilla Firefox browser
Internet Explorer Driver - For Internet Explorer browser
Chrome Driver - For Google Chrome browser
HtmlUnit Driver - GUI-Less(Headless) browser for Java programs
Opera Driver - For Opera browser
Q #198) Tell Me WebDriver Supported Mobile Testing Drivers?
Answer : We can get support of mobile application testing using Selenium webdriver. Selenium
WebDriver supports bellow given drivers to test mobile application.
AndroidDriver
OperaMobileDriver
IPhoneDriver
Q #199) Which Programming Languages Supported By Selenium WebDriver To Write Test Cases?
Answer : Selenium WebDriver Is very wast API and It support many different languages to write test
cases for your software web application. List of WebDriver supported languages are as bellow.
Java -> View Tutorials
C#
Python
Ruby
Perl
PHP
Q #200) Which Different Element Locators Supported By Selenium WebDriver?
Answer : Selenium WebDriver supports bellow given element locators.
XPath Locator -> View Example
CSSSelector Locator -> View Example
ClassName Locator -> View Example
ID Locator -> View Example
Name Locator -> View Example
LinkText Locator -> View Example
PartialLinkText Locator -> View Example
TagName Locator -> View Example
Selenium Notes Page 46
Selenium Interview Questions
Selenium Notes Page 47
Ques 1) What are the annotations used in TestNG ?
Ans: @Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass,
@BeforeMethod, @AfterMethod.
Ques 2) How do you read data from excel ?
FileInputStream fis = new FileInputStream(“path of excel file”);
Workbook wb = [Link](fis);
Sheet s = [Link](“sheetName”);
String value = [Link](rowNum).getCell(cellNum).getStringCellValue();
Ques 3) What is the use of xpath ?
Ans- it is used to find the WebElement in web page. It is very useful to identify the dynamic web
elements.
Ques 4) What are different types of locators ?
Ans- There are 8 types of locators and all are the static methods of the By class.
[Link](), [Link](), [Link](), [Link](), [Link](), [Link](), [Link],
[Link]().
Ques 5) What is the difference between Assert and Verify?
Ans- Assert- it is used to verify the result. If the test case fail then it will stop the execution of the
test case there itself and move the control to other test case.
Verify- it is also used to verify the result. If the test case fail then it will not stop the execution of that
test case.
Ques 6) What is the alternate way to click on login button?
Ans- use submit() method but it can be used only when attribute type=submit.
Ques 7) How do you verify if the checkbox/radio is checked or not ?
Ans- We can use isSelected() method.
Syntax –
[Link]([Link]("xpath of the checkbox/radio button")).isSelected();
If the return value of this method is true then it is checked else it is not.
Ques 8) How do you handle alert pop-up ?
Selenium Notes Page 48
Ans- To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or
cancle then move control back to main page.
Syntax-
String mainPage = [Link]();
Alert alt = [Link]().alert(); // to move control to alert popup
[Link](); // to click on ok.
[Link](); // to click on cancel.
//Then move the control back to main web page-
[Link]().window(mainPage); → to switch back to main page.
Ques 9) How do you launch IE/chrome browser?
Ans- Before launching IE or Chrome browser we need to set the System property.
//To open IE browser
[Link](“[Link]”,”path of the [Link] file ”);
WebDriver driver = new InternetExplorerDriver();
//To open Chrome browser → [Link](“[Link]”,”path of the
[Link] file ”);
WebDriver driver = new ChromeDriver();
Ques 10) How to perform right click using WebDriver?
Ans- Use Actions class
Actions act = new Actions(driver); // where driver is WebDriver type
[Link](webElement).perform();
[Link]().perform();
Ques 11) How do perform drag and drop using WebDriver?
Ans- Use Action class
Actions act = new Actions(driver);
WebElement source = [Link]([Link](“ -----”)); //source ele which you want to drag
WebElement target = [Link]([Link](“ -----”)); //target where you want to drop
Selenium Notes Page 49
[Link](source,target).perform();
Ques 12) Give the example for method overload in WebDriver.
Ans- frame(string), frame(int), frame(WebElement).
Ques 13) How do you upload a file?
Ans- To upload a file we can use sendKeys() method.
[Link]([Link](“input field”)).sendKeys(“path of the file which u want to upload”);
Ques 14) How do you click on a menu item in a drop down menu?
Ans- If that menu has been created by using select tag then we can use the methods selectByValue()
or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.
If the menu has not been created by using the select tag then we can simply find the xpath of that
element and click on that to select.
Ques 15) How do you simulate browser back and forward ?
[Link]().back();
[Link]().forward();
Ques 16) How do you get the current page URL ?
[Link]();
Ques 17) What is the difference between ‘/’ and ‘//’ ?
Ans- //- it is used to search in the entire structure.
/- it is used to identify the immediate child.
Ques 18) What is the difference between findElement and findElements?
Ans- Both methods are abstract method of WebDriver interface and used to find the WebElement in
a web page.
findElement() – it used to find the one web element. It return only one WebElement type.
findElements()- it used to find more than one web element. It return List of WebElements.
Ques 19) How do you achieve synchronization in WebDriver ?
Ans- We can use implicit wait.
Syntax- [Link]().timeouts().implicitlyWait(10,[Link]);
Selenium Notes Page 50
Here it will wait for 10sec if while execution driver did not find the element in the page immediately.
This code will attach with each and every line of the script automatically. It is not required to write
every time. Just write it once after opening the browser.
Ques 20) Write the code for Reading and Writing to Excel through Selenium ?
FileInputStream fis = new FileInputStream(“path of excel file”);
Workbook wb = [Link](fis);
Sheet s = [Link]("sheetName");
String value = [Link](rowNum).getCell(cellNum).getStringCellValue(); // read data
[Link](rowNum).getCell(cellNum).setCellValue("value to be set"); //write data
FileOutputStream fos = new FileOutputStream(“path of file”);
[Link](fos); //save file
Ques 21) How to get typed text from a textbox ?
Ans- use getAttribute(“value”) method by passing arg as value.
String typedText = [Link]([Link]("xpath of box")).getAttribute("value"));
Ques 22) What are the different exceptions you got when working with WebDriver ?
Ans- ElementNotVisibleException, ElementNotSelectableException, NoAlertPresentException,
NoSuchAttributeException, NoSuchWindowException, TimeoutException, WebDriverException etc.
Ques 23) What are the languages supported by WebDriver ?
Ans- Python, Ruby, C# and Java are all supported directly by the development team. There are also
webdriver implementations for PHP and Perl.
Ques 24) How do you clear the contents of a textbox in selenium ?
Ans- Use clear() method.
[Link]([Link]("xpath of box")).clear();
Ques 25) What is a Framework ?
Ans- A framework is set of automation guidelines which help in
Maintaining consistency of Testing, Improves test structuring, Minimum usage of code, Less
Maintenance of code, Improve re-usability, Non Technical testers can be involved in code, Training
period of using the tool can be reduced, Involves Data wherever appropriate.
There are five types of framework used in software automation testing:
Selenium Notes Page 51
1-Data Driven Automation Framework
2-Method Driven Automation Framework
3-Modular Automation Framework
4-Keyword Driven Automation Framework
5-Hybrid Automation Framework , its basically combination of different frameworks. (1+2+3).
Ques 26) What are the prerequisites to run selenium webdriver?
Ans- JDK, Eclipse, WebDriver(selenium standalone jar file), browser, application to be tested.
Ques 27) What are the advantages of selenium webdriver?
Ans- a) It supports with most of the browsers like Firefox, IE, Chrome, Safari, Opera etc.
b) It supports with most of the language like Java, Python, Ruby, C# etc.
b) Doesn’t require to start server before executing the test script.
c) It has actual core API which has binding in a range of languages.
d) It supports of moving mouse cursors.
e) It support to test iphone/Android applications.
Ques 28) What is WebDriverBackedSelenium ?
Ans- WebDriverBackedSelenium is a kind of class name where we can create an object for it as
below:
Selenium wbdriver= new WebDriverBackedSelenium(WebDriver object name, "URL path of
website")
The main use of this is when we want to write code using both WebDriver and Selenium RC , we
must use above created object to use selenium commands.
Ques 29) How to invoke an application in webdriver ?
[Link](“url”); or [Link]().to(“url”);
Ques 30) What is Selenium Grid ?
Ans- Selenium-Grid allows you to run your tests on different machines against different browsers in
parallel. That is, running multiple tests at the same time against different machines, different
browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It
allows for running your tests in a distributed test execution environment.
Selenium Notes Page 52
Ques 31) How to get the number of frames on a page ?
List <WebElement> framesList = [Link]([Link]("//iframe"));
int numOfFrames = [Link]();
Ques 32) How do you simulate scroll down action ?
Ans- Use java script to scroll down-
JavascriptExecutor jsx = (JavascriptExecutor)driver;
[Link]("[Link](0,4500)", ""); //scroll down, value 4500 you can change as per
your req
[Link]("[Link](450,0)", ""); //scroll up
ex-
public class ScrollDown {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
[Link]().timeouts().implicitlyWait(10, [Link]);
[Link]("[Link]
sid=2oq,c1r&otracker=hp_nmenu_sub_women_1_View%20all");
[Link]().window().maximize();
}
Ques 33) What is the command line we have to write inside a .bat file to execute a selenium
project when we are using testng ?
Ans- java -cp bin;jars/* [Link] [Link]
Ques 34) Which is the package which is to be imported while working with WebDriver ?
Ans- [Link]
Ques 35) How to check if an element is visible on the web page ?
Ans- use isDisplayed() method. The return type of the method is boolean. So if it return true then
element is visible else not visible.
[Link]([Link]("xpath of elemnt")).isDisplayed();
Ques 36) How to check if a button is enabled on the page ?
Ans- Use isEnabled() method. The return type of the method is boolean. So if it return true then
button is enabled else not enabled.
Selenium Notes Page 53
[Link]([Link]("xpath of button")).isEnabled();
Ques 37) How to check if a text is highlighted on the page ?
Ans- To identify weather color for a field is different or not-
String color = [Link]([Link]("//a[text()='Shop']")).getCssValue("color");
String backcolor = [Link]([Link]("//a[text()='Shop']")).getCssValue("background-
color");
[Link](color);
[Link](backcolor);
Here if both color and back color different then that means that element is in different color.
Ques 38) How to check the checkbox or radio button is selected ?
Ans- Use isSelected() method to identify. The return type of the method is boolean. So if it return
true then button is selected else not enabled.
[Link]([Link]("xpath of button")).isSelected();
Ques 39) How to get the title of the page ?
Ans- Use getTitle() method.
Syntax- [Link]();
Ques 40) How do u get the width of the textbox ?
[Link]([Link](“xpath of textbox ”)).getSize().getWidth();
[Link]([Link](“xpath of textbox ”)).getSize().getHeight();
Ques 41) How do u get the attribute of the web element ?
Ans- [Link]([Link](“img”)).getAttribute(“src”) will give you the src attribute of this
tag. Similarly, you can get the values of attributes such as title, alt etc.
Similarly you can get CSS properties of any tag by using getCssValue(“some propety name”).
Ques 42) How to check whether a text is underlined or not ?
Ans- Identify by getCssValue(“border-bottom”) or sometime getCssValue(“text-decoration”) method
if the
cssValue is 'underline' for that WebElement or not.
ex- This is for when moving cursor over element that is going to be underlined or not-
Selenium Notes Page 54
public class UnderLine {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
[Link]().timeouts().implicitlyWait(10, [Link]);
[Link]("[Link]
gfe_rd=ctrl&ei=bXAwU8jYN4W6iAf8zIDgDA&gws_rd=cr");
String cssValue= [Link]([Link]("//a[text()='Hindi']")).getCssValue("text-decoration");
[Link]("value"+cssValue);
Actions act = new Actions(driver);
[Link]([Link]([Link]("//a[text()='Hindi']"))).perform();
String cssValue1= [Link]([Link]("//a[text()='Hindi']")).getCssValue("text-
decoration");
[Link]("value over"+cssValue1);
[Link]();
}
Ans- Identify by getCssValue(“border-bottom”) or sometime getCssValue(“text-decoration”) method
if the
cssValue is 'underline' for that WebElement or not.
ex- This is for when moving cursor over element that is going to be underlined or not-
public class UnderLine {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
[Link]().timeouts().implicitlyWait(10, [Link]);
[Link]("[Link]
gfe_rd=ctrl&ei=bXAwU8jYN4W6iAf8zIDgDA&gws_rd=cr");
String cssValue= [Link]([Link]("//a[text()='Hindi']")).getCssValue("text-decoration");
[Link]("value"+cssValue);
Selenium Notes Page 55
Actions act = new Actions(driver);
[Link]([Link]([Link]("//a[text()='Hindi']"))).perform();
String cssValue1= [Link]([Link]("//a[text()='Hindi']")).getCssValue("text-
decoration");
[Link]("value over"+cssValue1);
[Link]();
Ques 43) How to change the URL on a webpage using selenium web driver ?
[Link](“url1”);
[Link](“url2”);
Ques 44) How to hover the mouse on an element ?
Actions act = new Actions(driver);
[Link](webelement); //webelement on which you want to move cursor
Ques 45) What is the use of getOptions() method ?
Ans- getOptions() is used to get the selected option from the dropdown list.
Ques 46) What is the use of deSelectAll() method ?
Ans- It is used to deselect all the options which have been selected from the dropdown list.
Ques 47) Is WebElement an interface or a class ?
Ans- WebDriver is an Interface.
Ques 48) FirefoxDriver is class or an interface and from where is it inherited ?
Ans- FirefoxDriver is a class. It implements all the methods of WebDriver interface.
Ques 49) Which is the super interface of webdriver ?
Ans- SearchContext.
Ques 50) What is the difference b/w close() and quit()?
Ans- close() – it will close the browser where the control is.
quit() – it will close all the browsers opened by WebDriver.
Selenium Notes Page 56
Ques 51) Can we enter text without using sendKeys() ?
Ans – Yes we can enter text without using sendKeys() method. We have to use combination of
javascript and wrapper classes with WebDriver extension class, check the below code-
public static void setAttribute(WebElement element, String attributeName, String value)
WrapsDriver wrappedElement = (WrapsDriver) element;
JavascriptExecutor driver = (JavascriptExecutor)[Link]();
[Link]("arguments[0].setAttribute(arguments[1],arguments[2])", element,
attributeName, value);
call the above method in the test script and pass the text field attribute and pass the text you want
to enter.
Ques 52) There is a scenario whenever “[Link]()” function fails automatically it has to
take screenshot. How can you achieve this ?
Ans- By using EventFiringWebDriver.
Syntax-EventFiringWebDriver eDriver=new EventFiringWebDriver(driver);
File srcFile = [Link]([Link]);
[Link](srcFile, new File(imgPath));
Ques 53) How do you handle https website in selenium ?
Ans- By changing the setting of FirefoxProfile.
Syntax-public class HTTPSSecuredConnection {
public static void main(String[] args){
FirefoxProfile profile = new FirefoxProfile();
[Link](false);
WebDriver driver = new FirefoxDriver(profile);
[Link]("url");
}
}
Ques 54) How to login into any site if its showing any authetication popup for user name and pass ?
Selenium Notes Page 57
Ans – pass the username and password with url.
Syntax- [Link]
ex- [Link]
Ques 55) What is the name of Headless browser.
Ans- HtmlUnitDriver.
Ques 56) Open a browser in memory means whenever it will try to open a browser the browser page
must not come and can perform the operation internally.
Ans- use HtmlUnitDriver.
ex-
public class Memory {
public static void main(String[] args) {
HtmlUnitDriver driver = new HtmlUnitDriver(true);
[Link](false);
[Link]().timeouts().implicitlyWait(10, [Link]);
[Link]("[Link]
[Link]([Link]());
}
Ques 56) What are the benefits of using TestNG ?
a) TestNG allows us to execute of test cases based on group.
b) In TestNG Annotations are easy to understand.
c) Parallel execution of Selenium test cases is possible in TestNG.
d) Three kinds of report generated
e) Order of execution can be changed
f) Failed test cases can be executed
g) Without having main function we can execute the test method.
Selenium Notes Page 58
h) An xml file can be generated to execute the entire test suite. In that xml file we can rearrange
our execution order and we can also skip the execution of particular test case.
Ques 57) How do you take screen shot without using EventFiringWebDriver ?
File srcFile = ((TakeScreenshot)driver).getScreenshotAs([Link]); //now we can do anything
with this screenshot
like copy this to any folder-
[Link](srcFile,new File(“folder name where u want to copy/file_name.png”));
Ques 58) How do you send ENTER/TAB keys in WebDriver ?
Ans- use click() or submit() [submit() can be used only when type=’submit’]) method for ENTER. Or
use Actions class to press keys.
For Enter-
[Link]([Link]);
For Tab-
[Link]([Link]);
where act is Actions class type. ( Actions act = new Actions(driver); )
Ques 59) What is Datadriven framework & Keyword Driven ?
Ans- Datadriven framework- In this Framework , while Test case logic resides in Test Scripts, the Test
Data is separated and kept outside the Test [Link] Data is read from the external files (Excel
File) and are loaded into the variables inside the Test Script. Variables are used both for Input values
and for Verification values.
Keyword Driven framework- The Keyword-Driven or Table-Driven framework requires the
development of data tables and keywords, independent of the test automation tool used to execute
them . Tests can be designed with or without the Application. In a keyword-driven test, the
functionality of the application-under-test is documented in a table as well as in step-by-step
instructions for each test.
Ques 60) While explaining the framework, what are points which should be covered ?
a) What is the frame work.
b) Which frame work you are using.
c) Why This Frame work.
d) Architecture.
e) Explanation of every component of frame work.
Selenium Notes Page 59
f) Process followed in frame work.
g) How & when u execute the frame work.
h) Code (u must write code and explain).
i) Result and reporting .
j) You should be able to explain it for 20 Minutes.
Ques 61) How to switch back from a frame ?
Ans- use method defaultContent().
Syntax – [Link]().defaultContent();
Ques 62) How to type text in a new line inside a text area ?
Ans- Use \n for new line.
ex- [Link](“Sanjay_Line1.\n Sanjay_Line2.”);
ex- [Link](“Sanjay_Line1.\n Sanjay_Line2.”);
it will type in text box as-
Sanjay_Line1.
Sanjay_Line2.
Ques 63) What is the use of AutoIt tool ?
Ans- Some times while doing testing with selenium, we get stuck by some interruptions like a
window based pop up. But selenium fails to handle this as it has support for only web based
application. To overcome this problem we need to use AutoIT along with selenium script. AutoIT is a
third party tool to handle window based applications. The scripting language used is in VBScript.
Ques 64) How to perform double click using WebDriver ?
Ans- use doubleClick() method.
Syntax- Actions act = new Actions(driver);
[Link](webelement);
Ques 65) How to press Shift+Tab ?
String press = [Link]([Link],[Link]);
[Link](press);
Selenium Notes Page 60
Ques 66) What is the use of contextClick() ?
Ans- It is used to right click.
Ques 67) What is the difference b/w getWindowHandles() and getWindowHandle() ?
Ans- getWindowHandles()- is used to get the address of all the open browser and its return type is
Iterator<String>.
getWindowHandle()- is used to get the address of the current browser where the conrol is and
return type is String.
Ques 68) How do you accommodate project specific methods in your framework ?
Ans- 1st go through all the manual test cases and identify the steps which are repeating. Note down
such steps and make them as methods and write into ProjectSpecificLibrary.
Ques 69) What are different components of your framework ?
Ans- Library- Assertion, ConfigLibrary, GenericLibrary, ProjectSpecificLibrary, Modules.
Drivers folder, Jars folder, excel file.
Ques 70) What are the browsers supported by Selenium IDE ?
Ans- Mozilla FireFox only. Its an Firefox add on.
Ques 71) What are the limitations of Selenium IDE ?
a) It does not supports looping or conditional statements. Tester has to use native languages to write
logic in the test case.
b) It does not supports test reporting, you have to use selenium RC with some external reporting
plugin like TestNG or JUint to get test execution report.
c) Error handling is also not supported depending on the native language for this.
d) Only support in Mozilla FireFox only. Its an Firefox add on.
Ques 72) How to check all checkboxes in a page ?
List<webElement> chkBox = [Link]([Link](“//htmltag[@attbute='checkbox']”));
for(int i=0; i<=[Link](); i++){
[Link](i).click();
}
Ques 73) Count the number of links in a page.
Ans- use the locator [Link] and find the elements for the tag //a then use loop to count the
number of elements found.
Selenium Notes Page 61
Syntax- int count = 0;
List<webElement> link = [Link]([Link](“a”));
[Link]([Link]()); // this will print the number of links in a page.
Ques 74) How do you identify the Xpath of element on your browser ?
And- to find the xpath , we use Firebug addons on firefox browser and to identify the xpath written
we use Firepath addons.
Syntax- //htmltag[@attname='attvalue'] or //html[text()='textvalue'] or
//htmltag[contains(text(),'textvalue')] or //htmltag[contains(@attname,'attvalue')]
Ques 75) What is Selenium Webdriver ?
Ans- WebDriver is the name of the key interface against which tests should be written in Java. All the
methods of WebDriver have been implementated by RemoteWebDriver.
Ques 76) What is Selenium IDE ?
Ans- Selenium IDE is a complete integrated development environment (IDE) for Selenium tests. It is
implemented as a Firefox Add-On, and allows recording, editing, and debugging tests. It was
previously known as Selenium Recorder.
Scripts may be automatically recorded and edited manually providing autocompletion support and
the ability to move commands around quickly.
Scripts are recorded in Selenese, a special test scripting language for Selenium. Selenese provides
commands for performing actions in a browser (click a link, select an option), and for retrieving data
from the resulting pages.
Ques 77) What are the flavors of selenium ?
Ans- selenium IDE, selenium RC, Selenium WebDriver and Selenium Grid.
Ques 78) What is selenium ?
Ans- Its an open source Web Automation Tool. It supports all types of web browsers. Despite being
open source its actively developed and supported.
Ques 79) Advantages of selenium over other tools ?
a) Its free of cost,
b) it supports many languages like Java, C#, Ruby, Python etc.,
c) it allows simple and powerful DOM-level testing etc.
Ques 80) What is main difference between RC and webdriver ?
Selenium Notes Page 62
Ans- Selenium RC injects javascript function into browsers when the web page is loaded.
Selenium WebDriver drives the browser using browser’s built-in support.
Ques 81) Why you choose webdriver over RC ?
a) Native automation faster and a little less prone to error and browser configuration,
b) Does not Requires Selenium-RC Server to be running
c) Access to headless HTMLUnitDriver can allow really fast tests
d) Great API etc.
Ques 82) Which one is better xpath or CSS ?
Ans- xpath.
Ques 83) How will you handle dynamic elements ?
Ans- By writing relative xpath.
Ques 84) what are the different assertions or check points used in your script ?
Ans- The common types of validations are:
a) Is the page title as expected,
b) Validations against an element on the page,
c) Does text exist on the page,
d) Does a javascript call return an expected value.
method used for validation – [Link]();
Ques 85) What is actions class in WebDriver ?
Ans- Actions class is used to control the actions of mouse.
Ques 86) What is the difference between @BeforeMethod and @BeforeClass ?
Ans- @BeforeMethod- this will execute before every @Test method.
@BeforeClass- this will execute before every class.
Ques 87) What are the different attributes for @Test annotation ?
Ans- alwaysRun, dataProvider, dependsOnMethods, enabled, expectedExceptions, timeOut etc.
ex- @Test(expectedExceptions = [Link])
Selenium Notes Page 63
@Test(timeOut = 2000)
Ques 88) Can we run group of test cases using TestNG ?
Ans- yes.
Ques 89) What is object repository ?
Ans- An object repository is a very essential entity in any UI automation tool. A repository allows a
tester to store all the objects that will be used in the scripts in one or more centralized locations
rather than letting them be scattered all over the test scripts. The concept of an object repository is
not tied to WET alone. It can be used for any UI test automation. In fact, the original reason why the
concept of object repositories were introduced was for a framework required by QTP.
Ques 90) What are oops concepts ?
a) Encapsulation,
b) Abstraction,
c) Polymorphism,
d) Inheritance.
Ques 91) What is inheritance ?
Ans- Inherit the feature of any class by making some relations between the class/interface is known
as inheritance.
Ques 92) What is difference between overload and override ?
Ans- The methods by passing different arguments list/type is known as overloading of methods
while having the same method signature with different method body is known as method overriding.
Ques 93) Does java supports multiple inheritance ?
Ans- Interface supports multiple inheritance but class does not support.
Ques 94) Write a java program for swapping of two numbers ?
public class Swapping{
public static void main(String[] args){
Scanner in = new Scanner([Link]);
[Link](“enter the 1st num”);
int a = [Link]();
[Link](“enter the 2nd num”);
Selenium Notes Page 64
int b = [Link]();
[Link](“before swapping a=”+a+” and b= ”+b);
int x = a;
a = b;
b = x;
[Link](“After swapping a=”+a+” and b= ”+b);
}
Ques 95) Write a java program for factorial of a given number.
public class Factorial{
public static void main(String args[]){
Scanner in = new Scanner([Link]);
[Link](“enter the num for which u want the factorial”);
int num = [Link]();
for(int i=num-1; i>0; i-- ){
num = num*i;
[Link](num);
Ques 96) What are the different access specifiers in Java?
Ans- private, default, protected and public.
Ques 97) Why do we go for automation testing ?
Ans- Reasons-
a) Manual testing of all work flows, all fields, all negative scenarios is time and cost consuming.
b) It is difficult to test for multi lingual sites manually.
Selenium Notes Page 65
c) Automation does not require human intervention. We can run automated test
unattended(Overnight).
d) Automation increases speed of test execution.
e) Automation helps increase test coverage.
f) Manual testing can become boring and hence error prone.
Ques 98) What is testing strategy ?
Ans- A Test Strategy document is a high level document and normally developed by project
manager. This document defines “Software Testing Approach” to achieve testing objectives. The Test
Strategy is normally derived from the Business Requirement Specification document.
Ques 99) write a code to make use of assert if my username is incorrect.
try{
[Link](expUserName, actUserName);
}catch(Exception e){
[Link](“name is invalid”);
Selenium Notes Page 66