Selenium Interview Questions - 3 To 5 Years
Selenium Interview Questions - 3 To 5 Years
• Test automation is a process that makes use of automation testing tools to execute pre-scripted
tests on applications, then compares the test results to the expected behavior and reports it to the
testers.
Benefits:
----------
• Selenium is an open source automation testing tool which is used to test web applications.
• Selenium testing tool consists of different set of tools in it like Selenium WebDriver, Selenium RC,
• Selenium provides a playback tool for authorising tests without need to learn a test scripting
languages.
--------------------------------------
• Selenium IDE
• Selenium RC
• Selenium Webdriver
• Selenium Grid
Selenium RC:
----------------
• It does not make direct calls to the browser. There will be an intermediate server.
Selenium Webdriver:
------------------------
• Faster
5.What is the latest version of Selenium jar file and how you will configure selenium jar file with
eclipse?
Latest version:
-----------------
• 3.141.59
---------------------
• After including Selenium jar into our project,right click the jar and give "add to build path" for
configuration.
• No,Google Chrome is not be supported by Selenium IDE.It supports only mozilla extentions.
• Chrome browser
• Internet Explorer
• safari browser
Browser Class
1. Firefox browser FirefoxDriver
2. Chrome browser ChromeDriver
3. IE InternetExplorerDriver
4. Safari browser SafariDriver
5. Opera browser OperaDriver
• Webdriver is a web automation framework that allows you to execute your tests againts different
• Webdriver also enables you to use a programming language in creating your test script.
• Webdriver is a interface.
11.What are the method names are available to get the title and url of the webpage?
close():
--------
-------
• It will close all the opened windows and browser will also be closed.
• close()
• findElement()
• findElements()
• get()
• getTitle()
• getCurrentUrl()
• manage()
• quit()
• switchTo()
• It is mainly used for providing the connection between the browser and local system.
• It acts as a bridge.
• id
• classname
• name
• Xpath
• CSSselector
• linkText
• partialLinkText
• tagname
16.Which locator is fastest in selenium?
17.How will you find the locators in selenium? write a code for it?
Code
-------
driverrefname.findElement(By.locator("values");
findElement
------------
findElements
---------------
• findElement - WebElement
• findElements - List<WebElement>
*By is an abstract class in which all the locator methods are available.
• WebElementRefname.sendKeys("values to be inserted");
*When multiple WebElements has same Xpath,we can give index for that to uniquely locate a
WebElement.
*syntax: (xpath)[index]
*WebElement is an interface.
• System is a class and setProperty is a method which accepts 2 arguments i.e key and path
---------------------------
• Absolute Xpath
• Relative Xpath
Absolute Xpath:
---------------
• It contains \
• Here we find path from root element <html> to desired WebElement tagname
Relative Xpath:
---------------
• It contains \\
• Here we find the path from the desired WebElement's tagname only
\:
---
• It is used to find path from root element <html> tagname to desired WebElement tagname
\\:
----
Xpath:
--------
• Xpath syntax is complex compared to css selector
CSS selector:
---------------
Radio button:
--------------
Check box:
------------
• For deselecting we have to select the same option one more time.
------------------------------
• JavaScriptExecutor js=(JavaScriptExecutor)driverRef;
• js.executeScript("arguments[0].click()",webElementRef);
• contains()
• starts-with()
35.How will you select a female Radio Button in facebook signup and write a code for it ?
*WebElement radioGender=driverRef.findElement(By.Xpath
("//input[@value='1']");
radioGender.click();
element.click();
• Stale Element means an old element or element that is no longer available in DOM.
• When the user refreshes the page or navigates into new page, DOM changes then the
• If we try to reuse the WebElement that became stale we will get StaleElementReferenceException.
• We can easily identify the step where the code getting exception.
• Eclipse debugger.
//tagname[text()='textname']
//tagname[contains(text(),'partial text')]
//tagname[contains(text(),'partial text')]
System.out.Println(webElemRef.getText();)
43.What is the method used to get the text from the webpage?
• getAttribute("attributename") method is used to get the attribute value of the given attribute
• getAttribute("value") also used to get the input what we have passed to a webElement
• Thread.sleep(milliseconds) is used to make your program to wait for some defined time to avoid
48.Whether it is possible to get the text from webpage without using getText()?
• No,it is not possible to get the text from webpage without using getText() method.
• When we place cursor over some content in the webpage,it will display a list of content.For
refName.moveToElement(WebElementrefName).perform();
*Actions is a class.
refName.dragAndDrop(sourceWebElement,destWebElement).perform();
(or)
refName.clickAndHold(WebElementRef).perform();
refName.release(WebElementRef).perform();
• Actions class is used to perform mouse operations such as mouse hover action,drag and
• This class will contain more methods for performing each of the mouse actions.
• In some webpages,the design will be like we need to drag and drop the content to the specified
field.
• That we can achieve only through mouse.For mouse operations,we use Actions class in Selenium.
• Actions-class
• The menu list disappear with in the fractions of seconds before Selenium identify the next
• click action on it.So,it is better to use perform() method.Only then the desired mouse action can be
performed.
• moveToElement() method will be used to move the cursor to the particular element.
• contextClick()
• doubleClick()
• dragAndDrop()
• Robot class is a class which is used to perform the keyboard actions in java.
• It throws AWTException.
refname.keyPress(KeyEvent_vk_anykeyyouwant);
refname.keyRelease(KeyEvent_vk_anykeyyouwant);
vk-->virtual keyboard
• java.awt
• AWTException
66.Which method is used to perform rightClick operation?
• By using getScreenShotAs() method from TakesScreenShot interface we can take the screenshot.
• TakesScreenShot is a interface.
• OutputType.FILE
• OutputType.BYTES
• OutputType.BASE64
• JavaScriptExeceutor is an interface.
• By using Select class,we can select the options from single select and multi select dropdown.
• Select is a class.
75.Write a code to print all the options in DropDown?
• getOptions() method will return List<WebElement> then iterating each WebElement and using
getText() method
*isMultiple() method from Select class can be used to check whether the dropdown is single select
• selectByValue();
• selectByVisibleText();
• selectByIndex();
• getOptions();
• getAllSelectedoptions();
• getFirstselectedoptions();
• isMultiple();
• deSelectByValue();
• deSelectByVisibleText();
• deSelectByIndex();
• deSelectAll()
Yes, we can deselect the options in dropdown using the below methods.
• deSelectByValue();
• deSelectByVisibleText();
• deSelectByIndex();
• deSelectAll()
*By using getAllSelectedoptions() method we can get all the selected WebElements.
refName.getAllSelectedoptions();
*getAllSelectedoptions() method will return List<WebElement> then iterating each WebElement and
using getText() method
• selectByValue() -void
• selectByVisibleText() -void
• selectByIndex() -void
• getOptions() -List<WebElement>
• getAllSelectedoptions() -List<WebElement>
• getFirstselectedoption() -WebElement
• isMultiple() -boolean
• deSelectByValue() -void
• deSelectByVisibleText() -void
• deSelectAll() -void
• deSelectByIndex() -void
*Whenever we have multiple windows,to switch the program control between different windows,
• using window id
83.Write a method used to get the window id of all the windows opened?
84.What are the different types of arguments you can pass in windows()?
• id
• url
• title
85.When you have multiple windows opened ,how to directly switch from parent window to 8 th
child window?
List<String> allWindowsId=(List<String>)driver.getWindowHandles();
driver.SwitchTo().window(allWindowsId.get(7));
*List<WebElement> rowRef=driver.findElements(By.tagname("tr"));
WebElement firstRow=rowRef.get(0);
List<WebElement> colRef=firstRow.findElements(By.tagname("td"));
for(int j=0;j<colRef.size();j++)
List<WebElement> col=colRef.get(j);
String colText=col.getText();
System.out.println(colText);
List<WebElement> rowRef=driver.findElements(By.tagname("tr"));
for(int i=o;i<ref.size();i++)
WebElement row=rowRef.get(i);
List<WebElement> heaRef=row.findElements(By.tagname("th"));
for(int j=0;j<heaRef.size();j++){
System.out.println(head);
List<WebElement> dataRef=row.findElements(By.tagname("td"));
for(int j=0;j<colRef.size();j++)
List<WebElement> col=colRef.get(j);
String colText=col.getText();
System.out.println(colText);
}
}
*Wait operation is used to make your script to wait the for some time till webpage is getting loaded
completely to
*Static wait
=========
Even though the locator is found, it will wait for maximum time
Thread.sleep(milliseconds);--->throws InterruptedException
Eg:
*Dynamic wait:
===========
• *If the locator is found within some seconds,it will not wait till the maximum time.
• *Implicit wait
• *Explicit wait
91.What are the difference between implict wait and explict wait?
Implict wait:
--------------
Explict wait:
---------------
• getFirstSelectedOption() method used to get the first selected option from drop down.
• From the WebElement we can get the text using getText() method.
• Alert is an information box displayed in the webpage to give some information to the user.
• When any Alert present in the webpage,without handling the alert user cannot do the next
• accept()
• dismiss()
• sendkeys()
• *Alert is an interface.
• WebDriver -->interface
• new -->keyword
• ChromeDriver-->Class name
• WebElement
• Name
• Id
• Index
• isSelected() -To check whether checkbox ,radio box or dropdown value is selected or not.
• isEnabled() -To check whether button and textbox is in enabled state or not.
• Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as
• The user may configure the wait to ignore specific types of exceptions while waiting, such as
Following:
----------
sibling:
--------
• *denotes the following siblings of the context node. Siblings are at the same level of the current
node .
Parent:
--------
Child :
-------
Preceding:
----------
To get the value of a given CSS property of a WebElement such as font color,alignment,size etc
104.What is the difference between partial link text and link text?
LinkText:
-----------
PartialLinkText:
----------------
• In the PartialLinkText we take partial text from a link's text(link must be a hyperlink)
• WebDriver
• JavascriptExecutor
• Alert
• TakeScreenShot
106.What is a broken link and how do you find it?
For checking the broken links, you will need to do the following steps.
--------------------------------------------------------------------------
• Collect all the links in the web page based on <a> tag.
• Send HTTP request for the link and read HTTP response code.
• Find out whether the link is valid or broken based on HTTP response code.
• Without frameworks, we will place the “code” as well as “data” in the same place which is neither
• Using Frameworks, produce beneficial outcomes like increased code re-usage, higher portability,
• If we use get() method, it is used to launch the given url and get() method will wait till the page
loads completely
• If we use navigate() method, we can perform back(), refresh() and forword() action since it stores
browser cookies and navigate() method will not wait till the page loads completely.
Core Java Interview Questions and Answers
1.What is java?
• 1. Platform independent
• 2. Open source
• 3. Multithreading
• 4. More secure
• 5. Portable
• During the compilation the java program is converted into byte code(not machine specific).
• Bytecode can be runned by jvm of any platform.
• So code developed in one platform is capable of running in all other platform.
• A program in which source code is available to the general public for use and/or modification
from its original design at free of cost is called open source.
• Notepad
• Netbeans
• Eclipse
• JDeveloper(oracle)
• RAD(IBM)
JDK:
----
JRE:
----
JVM:
----
Class:
------
• Class is a collection of objects and methods
• Class contains attributes(variables and methods) that are common to all the objects created in a
class.
Method:
-------
Object:
-------
• byte
• short
• int
• long
• float
• double
• boolean
• char
• String
• nextByte();
• nextShort();
• nextInt();
• nextLong();
• nextFloat();
• nextDouble();
• next().charAt(0);
• next();
• nextLine();
• nextBoolean();
• Accessing one class Properties in another class without multiple object creation.
• It avoids time and memory wastage.
• It ensures code reusability
18.What are the ways to access the methods /data from another class?
• We can access the another class methods either by creating object or using extends keyword.
• Poly-many.
• Morphism-forms.
• Taking more than one forms is called polymorphism or one task implemented in many ways.
• Class-name
• Method-same
• Argument-differ based on datatype,order,number
• Single Inheritance
• Multilevel Inheritance
• Multiple Inheritance
• Hybrid Inheritance
• Hierarchical Inheritance
• Compilation error/syntax error-After extends keyword we can mention only one classname( , not
allowed)
• Priority problem-When multiple parent classes has methods with same name and
arguments,compiler will not know
which method should be called.
Multiple inheritance:
-------------------------
• More than one parent class directly supporting into same child class.
• Multiple inheritance not supported in java due to Compilation problem and priority problem
• We have achieve multiple inheritance in java through interface.
Multilevel inheritance:
-----------------------
• More than one parent class supporting into one child class in tree level structure.
• It is supported in java
Public:
-------
Protected:
------------
• It will support only abstract method(without business logic), won't support non abstract
method(method with business logic)
• In interface "public abstract" is default.
• using "implements" keyword we can implement the interface in a class where we can write the
business logic for all
unimplemented methods.
Abstract class:
-----------------
Interface:
-----------
• equals();
• equalsignorecase();
• contains();
• split();
• toUpperCase();
• toLowerCase();
• subString();
• isEmpty();
• identifyHashCode();
• startsWith();
• endsWith();
• CompareTo();
• charAt();
• indexOf();
• lastIndexOf();
• replace();
• Constructor is a special method which is called by default when object is created for that
particular class.(implicit call)
• Class name and constructor name must be same.
• It doesn't have any return type.
• It supports method overloading but won't support method overriding.
• purpose of constructor:It is used to initialise the values to variables.
• Parameterized constructor
• Non parameterized constructor
• constructor is not directly called by your code, its called by memory allocation and object
initialisation in the run time.
• Its return value is opaque to the user so we cant mention it.
39.Can we declare constructor as 'private'?
• The process of calling one constructor from another constructor with respect to current object is
called constructor chaining.
• By using this() and super() methods we can achieve constructor chaining.
• When a variable is declared as static,then a single copy of variable is created and shared among all
object at class level.
• Static variable are essentially global variable.
• All the instance of the class share the same static variable.
• When a method is declared as static,we need not create object to call the paticular method.We
can call as Classname.methodname()
• Static method in java belong to the class(not to an object).
• They use no instance variables and will usually take the input from the parameters and perform
action on it,then return some result.
51.What is mean by final keyword and what's happend when we declare final as in
class,method,variable?
Final:
-----
Finally:
--------
• Code given inside finally block will always get executed whether exception occurs or not.
54.What is Exception?
• Exception is an unexpected event which when occurs in a program,your program will terminate
abnormally.
• We can avoid this abnormal termination using exception handling
mechanisms(try,catch,finally,throw,throws)
56.What are the difference between checked expection and unchecked expection?
Unchecked exception:
-------------------------
Checked exception:
----------------------
• Throwable
• Exception
• Yes we can have try block without catch block.But in that case finally block must be
present.(There will be no syntax error)
• Possible but we will not able to handle the exception without catch block.
59.Can we write multiple catch blocks under single try block?
62.What are the differences between final finally and finalize in java?
Final:
-----
Finally:
--------
• It’s a block of statement that definitely executes after the try catch block.
• Exception occurs or not,finally block always get executed.
Finalize:
---------
Throw:
------
• Throw is a keyword, using which we can throw any any exception.This keyword always given
inside the method.
• At a time we can throw only one exception using throw keyword.
Throws:
---------
Exception
Advantage:
-------------
70.What is collection ?
ArrayList:
----------
• Asynchronized
• It is not a thread safe
Vector:
-------
• Synchronized
• Thread safe
LinkedList:
-----------
• Insertion and deletion is a best one.
• Searching/retrieving is a worst.
• It’s makes performance issue.
ArrayList:
----------
74.Describe the Collections type hierarchy ? What are the main interfaces ?
Collection:
------------
• List
• Set
Hierarchy:
-----------
List:
----
• ArrayList
• LinkedList
• Vector
Set:
----
• Hashset
• LinkedHashSet
• Treeset
Map:
----
• HashMap
• LinkedHashMap
• Hashtable
• TreeMap
• ConcurrentHahMap
Set:
----
List:
-----
HashSet:
---------
TreeSet:
---------
• By addAll() we can convert List into set.(all the elements in list will get added to set)
78.What is map?
HashMap:
----------
Hashtable:
----------
Set:
----
Map:
----
• Yes,we can iterate the list using both normal and enhanced for loop.
• indexOf();
• get();
• lastIndexOf();
• HashMap :k?,v?
• LinkedHashMap:k?,v?
• TreeMap :k?,v?
• HashTable :k?,v?
• HashMap :k-1 null,v- n null
• LinkedHashMap:k-1 null,v- n null
• TreeMap :k-ignore null,v- allow null
• HashTable :k-ignore null,v- ignore null
• Set<Entry<key,value>>
87.Write the methods to get the key only and value only?
• mkdir();
• mkdirs();
• list();
• createNewFile();
• isDirectory();
• isFile();
• isHidden();
90.While creating a file if we not mention the format then under which format it will save the file?
• If we do not mention the file format it will automatically take format as file.
91.What are the difference between append and updating the file?
Enumeration:
--------------
Iterator:
---------
Enumerator:
------------
Iterator:
----------
ListIterator:
--------------
Enumerator Methods:
------------------
• hasMoreElements();
• nextElement();
Iterator Methods:
----------------
• hasNext();
• next();
• remove();
ListIterator Methods:
---------------------
• hasNext();
• next();
• remove();
• hasPrevious();
• previous();
• Statement which has control over the loop or program is called control statements.
• Example:if,if else,for,while,dowhile etc
Break:
------
Continue:
----------
----------
While:
------
Do While:
---------
if and if else
===============
if
--
if else
--------
• executes the else part when the condition becomes false and executes if part when condition
becomes true.
Immutable string:
-----------------
mutable string:
----------------
removeAll():
------------
• removeAll() is a method , it is used to compare the 2 lists and remove all the common values
retainAll():
------------
• retainAll() is a method, it is used to compare both lists and retains only the common values
Literal String:
---------------
Static memory:
--------------
• java.lang
equals:
-------
Hashcode:
----------
• collections.SynchronisedList(refName of array);