Selenium Webdriver Interview Question PDF
Selenium Webdriver Interview Question PDF
com
This is one of the common interview questions in any Automation testing job.
1
UnwiredLearning.com
It depends on Test case scenario complexity and length. I did automate 2-5
test scenarios per day when the complexity is limited. Sometimes just 1 or
fewer test scenarios in a day when the complexity is high.
6. What is a Framework?
If you are a beginner: No, I didn’t get a chance to create a framework. I have
used the framework which is already available.
If you are an experienced tester: Yes, I have created a framework. Or I have
involved in the creation of the framework.
9. What is Selenium?
2
UnwiredLearning.com
3. Selenium WebDriver
4. Selenium Grid
Selenese is the language which is used to write test scripts in Selenium IDE.
12. Which is the only browser that supports Selenium IDE to be used?
Firefox
3
UnwiredLearning.com
It allows running test cases in parallel thereby saving test execution time.
It allows multi-browser testing
It allows us to execute test cases on multi-platform
4
UnwiredLearning.com
Node is the machine which is attached to the hub. There can be multiple
nodes in Selenium Grid.
• Firefox Driver
• Gecko Driver
• InternetExplorer Driver
• Chrome Driver
• HTML Driver
• Opera Driver
• Safari Driver
• Android Driver
• iPhone Driver
• EventFiringWebDriver
• Java
• C#
• Python
• Ruby
• Perl
• PHP
• Windows
5
UnwiredLearning.com
• Linux
• Apple
• JUnit
• TestNG
1. ID
2. ClassName
3. Name
4. TagName
5. LinkText
6. PartialLinkText
7. XPath
8. CSS Selector
XPath is used to locate the elements. Using XPath, we could navigate through
elements and attributes in an XML document to locate web elements such as
textbox, button, checkbox, Image etc., in a web page.
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.
28. What is the difference between Absolute Path and Relative Path?
6
UnwiredLearning.com
Absolute XPath starts from the root node and ends with desired descendant
element’s node. It starts with top HTML node and ends with input node. It
starts with a single forward slash(/) as shown below.
/html/body/div[3]/div[1]/form/table/tbody/tr[1]/td/input
Relative XPath starts from any node in between the HTML page to the current
element’s node(last node of the element). It starts with a double
forward slash(//) as shown below.
//input[@id='email']
Assert: In simple words, if the assert condition is true then the program
control will execute the next test step but if the condition is false, the
execution will stop and further test step will not be executed.
Verify: In simple words, there won’t be any halt in the test execution even
though the verify condition is true or false.
Soft Assert: Soft Assert collects errors during @Test Soft Assert does not
throw an exception when an assert fails and would continue with the next step
after the assert statement.
7
UnwiredLearning.com
SearchContext.
8
UnwiredLearning.com
38. What are the different exceptions you have faced in Selenium
WebDriver?
1. ElementNotVisibleException
2. StaleElementReferenceException
This exception will be thrown when you are trying to locate a particular
element on webpage that is not currently visible eventhough it is present in
the DOM. Also sometimes, if you are trying to locate an element with the
xpath which associates with two or more element.
A stale element reference exception is thrown in one of two cases, the first
being more common than the second.
We face this stale element reference exception when the element we are
interacting is destroyed and then recreated again. When this happens the
reference of the element in the DOM becomes stale. Hence we are not able to
get the reference to the element.
• WebDriverException
• TimeoutException
• NoAlertPresentException
• NoSuchWindowException
9
UnwiredLearning.com
• NoSuchElementException
• TimeoutException
http://username:password@url
e.g. http://myUserName:[email protected]
In Selenium we could see three types of waits such as Implicit Waits, Explicit
Waits and Fluent Waits.
• Implicit Waits
• Explicit Waits
• Fluent Waits
Implicit waits tell to the WebDriver to wait for a certain amount of time before
it throws an exception. Once we set the time, WebDriver will wait for the
element based on the time we set before it throws an exception. The default
setting is 0 (zero). We need to set some wait time to make WebDriver to wait
for the required time.
FluentWait can define the maximum amount of time to wait for a specific
condition and frequency with which to check the condition before throwing an
“ElementNotVisibleException” exception.
10
UnwiredLearning.com
44. How to input text in the text box using Selenium WebDriver?
45. How to input text in the text box without calling the sendKeys()?
// To initialize js object
JavascriptExecutor JS = (JavascriptExecutor)webdriver;
// To enter username
JS.executeScript("document.getElementById(User').value='SoftwareTestingMa
terial.com'");
// To enter password
JS.executeScript("document.getElementById('Pass').value='tester'");
46. How to clear the text in the text box using Selenium WebDriver?
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath_of_element1")).sendKeys("Software
Testing Material Website");
driver.findElement(By.xpath("xpath_of_element1")).clear();
package softwareTestingMaterial;
11
UnwiredLearning.com
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
@Test
public void testmethod(){
System.setProperty("webdriver.chrome.driver", "D:\\Selenium
Environment\\Drivers\\chromedriver.exe");
String availableText =
driver.findElement(By.xpath("//*[@id='gbw']/div/div/div[1]/div[1]/a")).getTe
xt();
driver.findElement(By.id("form_1")).submit();
Alternatively, you can use click method on the element which does form
submission
12
UnwiredLearning.com
driver.findElement(By.xpath("xpath")).sendKeys(Keys.ENTER);
Thread.sleep(5000)
driver.get("https://www.softwaretestingmaterial.com");
driver.get(): To open an URL and it will wait till the whole page gets loaded
driver.navigate.get(): To navigate to an URL and It will not wait till the whole
page gets loaded
13
UnwiredLearning.com
driver.getCurrentUrl();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
14
UnwiredLearning.com
15
UnwiredLearning.com
Test cases may fail while executing the test scripts. While we are executing
the test cases manually we just take a screenshot and place in a result
repository. The same can be done by using Selenium WebDriver.
i. Application issues
ii. Assertion Failure
iii. Difficulty to find Webelements on the web page
iv. Timeout to find Webelements on the web page
To handle alerts popups we need to do switch to the alert window and call
Selenium WebDriver Alert API methods.
16
UnwiredLearning.com
(JavascriptExecutor(driver)).executeScript("document.getElementsByClassNa
me(ElementLocator).click();");
Test data can efficiently be read from excel using JXL or POI API. POI API has
many advantages than JXL.
Click here to see a practical example of using Apache POI.
No, It’s not possible to automate captcha and bar code reader.
Handling AJAX calls is one of the common issues when using Selenium
WebDriver. We wouldn’t know when the AJAX call would get completed and
the page has been updated. In this post, we see how to handle AJAX calls
using Selenium.
AJAX stands for Asynchronous JavaScript and XML. AJAX allows the web page
to retrieve small amounts of data from the server without reloading the entire
page. AJAX sends HTTP requests from the client to server and then process
the server’s response without reloading the entire page. To handle AJAX
controls, wait commands may not work. It’s just because the actual page is
not going to refresh.
When you click on a submit button, the required information may appear on
the web page without refreshing the browser. Sometimes it may load in a
second and sometimes it may take longer. We have no control over loading
time. The best approach to handle this kind of situations in selenium is to use
dynamic waits (i.e. WebDriverWait in combination with ExpectedCondition)
17
UnwiredLearning.com
1. titleIs() – The expected condition waits for a page with a specific title.
In QTP, there is an Object Repository concept. When a user records a test, the
objects and its properties are captured by default in an Object Repository. QTP
uses this Object Repository to play back the scripts. Coming to Selenium,
there is no default Object Repository concept. It doesn’t mean that there is no
Object Repository in Selenium. Even though there is no default one still we
could create our own. In Selenium, we call objects as locators (such as ID,
Name, Class Name, Tag Name, Link Text, Partial Link Text, XPath, and CSS).
Object repository is a collection of objects. One of the ways to create Object
Repository is to place all the locators in a separate file (i.e., properties file).
But the best way is to use Page Object Model. In the Page Object Model
Design Pattern, each web page is represented as a class. All the objects
related to a particular page of a web application are stored in a class.
18
UnwiredLearning.com
Page Object Model is a Design Pattern which has become popular in Selenium
Test Automation. It is widely used design pattern in Selenium for enhancing
test maintenance and reducing code duplication. Page object model (POM) can
be used in any kind of framework such as modular, data-driven, keyword
driven, hybrid framework etc. A page object is an object-oriented class that
serves as an interface to a page of your Application Under Test(AUT). The
tests then use the methods of this page object class whenever they need to
interact with the User Interface (UI) of that page. The benefit is that if the UI
changes for the page, the tests themselves don’t need to change, only the
code within the page object needs to change. Subsequently, all changes to
support that new UI is located in one place.
77. What is the difference between Page Object Model (POM) and
Page Factory?
Page Object is a class that represents a web page and hold the functionality
and members.
Page Factory is a way to initialize the web elements you want to interact with
within the page object when you create an instance of it.
19
UnwiredLearning.com
Object Repository – Each page will be defined as a java class. All the fields
in the page will be defined in an interface as members. The class will then
implement the interface.
There are two cases which are majorly used to upload a file in Selenium
WebDriver such as using SendKeys Method and using AutoIT Script.
driver.switchTo().frame();
We use JDBC Driver to connect the Database in Selenium (While using Java
Programming Language).
20
UnwiredLearning.com
21
UnwiredLearning.com
Sometimes, we may face a situation to get the data from the Database or to
modify (update/delete) the data from the Database. If we plan to automate
anything outside the vicinity of a browser, then we need to use other tools to
achieve our task. To achieve the Database connection and work on it, we need
to use JDBC API Driver.
The Java Database Connectivity (JDBC) API provides universal data access
from the Java programming language. Using the JDBC API, you can access
virtually any data source, from relational databases to spreadsheets and flat
files. It lets the user connect and interact with the Database and fetch the
data based on the queries we use in the automation script. JDBC is a SQL level
API that allows us to execute SQL statements. It creates a connectivity
between Java Programming Language and the database.
22
UnwiredLearning.com
driver.Manage().Cookies.DeleteAllCookies();
Here we have dealt with some important TestNG interview questions. If you
want to learn more interview questions related to TestNG then here you go.
We have a special post on TestNG Interview Questions. Also, you could
find TestNG Complete Tutorial here
@BeforeTest
@AfterTest
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod
@BeforeSuite
@AfterSuite
@BeforeGroups
@AfterGroups
@Test
96. What is TestNG Assert and list out some common Assertions
supported by TestNG?
23
UnwiredLearning.com
TestNG Asserts help us to verify the condition of the test in the middle of the
test run. Based on the TestNG Assertions, we will consider a successful test
only if it is completed the test run without throwing any exception.
Parameterized tests allow developers to run the same test over and over again
using different values.
• with testng.xml
• with Data Providers
Ans. TestNG listeners are used to configure reports and logging. One of the
most widely used listeners in TestNG is ITestListener interface. It has methods
like onTestStart, onTestSuccess, onTestFailure, onTestSkipped etc. We
should implement this interface creating a listener class of our own. Next, we
should add the listeners annotation (@Listeners) in the Class which was
created.
24