Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Interface:

A Java interface defines a set of methods but does not implement them. A class that
implements the interface agrees to implement all of the methods defined in the
interface.

An interface in java is a blueprint of a class. It has static constants and abstract


methods only.

The interface in java is a mechanism to achieve fully abstraction. There can be only
abstract methods in the java interface not method body. It is used to achieve fully
abstraction and multiple inheritance in Java.

Java Interface also represents IS-A relationship.

It cannot be instantiated just like abstract class.

Simplest definition of an Abstract method is:

"A method which is incomplete and to be completed in its child class is called an
abstract method".

Let's take a real world scenario. You have declared a class named Vehicle which
contains a method drive(). drive () defines the mechanism that how a particular
vehicle can be driven. Since there may be different driving mechanism for different
vehicles, we will not write the method definition for drive(). ie, we would declare
that method as abstract.

Now, let's assume that we have two classes Bike and Car and these both are
extending Vehicle. So, we can define our drive() method in Bike and Car classes as
per our requirements.

Here are some important point regarding abstract methods:

1) if you are declaring an abstract method, it must overridden in child class.

2) if a class contains minimum of one abstract method, it must be declared as


abstract class.

So here, Webdriver is the Interface


All Known Implementing Classes:
AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, Firef
oxDriver, HtmlUnitDriver, InternetExplorerDriver,IPhoneDriver, IPhoneSimulat
orDriver, RemoteWebDriver, SafariDriver

Basic methods of Webdriver:


Get();
Load a new web page in the current browser window.
getCurentURl();
Get a string representing the current URL that the browser is looking at.
getTitle()
The title of the current page
getPageSource()
Get the source of the last loaded page.
Quit();
Quits this driver, closing every associated window.
Close();
Close the current window, quitting the browser if it's the last window currently open.

Set Property :
All the browsers given exe files to invoke the browser from selenium. So we need
assign it before the webdriver launch
System.setproperty (“webdriver.chrome.driver”,
"D:\Selenium\chromedriver.exe")
It is (key, value) syntax where Key is webdriver.chrome.driver and value is
D:\Selenium\chromedriver.exe for chrome
For Firefox, Key is webdriver.gecko.driver and for IE, webdriver.ie.driver
Locators – 8
 ID
 Name
 Linktext
 Partial Linktext
 Tag Name
 Class Name
 CSS Selector
 Xpath
ID :
Driver.findelement(By.id(“”))
 If the id contains alphanumeric, it is dynamic and we shouldn’t use that
Name
Driver.findelement(By.name(“”))
Linktext
Driver.findelement(By.linkText(“”))
 Confirm the link object with anchor "a" tag
Class Name
Driver.findelement(By.classname(“”))
 Classes should not have spaces- Compound classes cannot be accepted
Xpath
 Right click on the DOM, click on copy , take the xpath, using xpath option
Driver.findelement(By.Xpath(“//*[@attribute = ‘value’]”))
CSS
 Right click on the DOM, click on copy , take the css using selector option
Driver.findelement(By.cssSelector(“//[attribute = ‘value’]”))

How to validate your xpath is correct?


 Find the xpath
 Navigate to console tab in Developers tools
 Type $x(“xpath”) and hit enter
 Mouse hover on the result which will highlight the element
How to validate your CSS Selector is correct?
 Find the cssselector
 Navigate to console tab in Developers tools
 Type $(“cssselector”) and hit enter
 Mouse hover on the result which will highlight the element
Customized Xpath and CSS

Xpath - //*[@attribute = ‘value’] or //tagName[@attribute = ‘value’]


CSS - //*[attribute = ‘value’] or tagName[attribute = ‘value’]

Below are only for CSS


If we know the id, use below

 tagName#id

If we know the classname, use below


 tagName.classname
Contains

//tagName[contains(@attribute=’value’)] - for Xpath

tagName(attribute*=’value’) - for CSS

Parent and child relationship

When we don’t have unique or static attributes, we have to write an xpath with
the help of parent or child xpath only

Identify the parent xpath and traverse the child using tagName

Siblings

U cannot travel between the siblings. You have to travel back to parent from child
and have to travel to the respected child

To travel between the siblings,

“Xpath/following-sibling:li[2]”

Where “li” is the tagName in the Udemy example

How to traverse back to parent from child?

“Xpath/parent:Ul[2]”

Where “Ul” is the tagName in the Udemy example

Difference between single (absolute) and double (Relative)slash in X-path?


 Single slash ( / ) start selection from the document node It allows you to
create ‘absolute’ path expressions
 Double slash ( // ) start selection matching anywhere in the document It
enables to create ‘relative’ path expressions.

How to identify using Text?

//tagName[text()= ‘Text’]
Static dropdowns

Static dropdowns will always have same values and it will have “Select” tag

Selenium itself having separate class called “Select” for this static dropdown

Create an object for the Select class and pass the respected element of the drop
down as an argument into that class.

Select obj = new Select(webelement)

After that,

Obj.selectbyValue (2) // Second value will be selected


Obj.selectbyIndex (6) // Fifth value will be selected
Obj.selectbyVisibletext (5 Adults) // 5 Adults value will be selected

Dynamic dropdowns
This is very simple , find the xpath of the required element and its count in overall
page.
For Example, if we are required to select the Chennai value from [To] in a Airport
sight, Chennai will be presented in both [From] and [To], Where From will the 1st
index and To is the 2nd index. So we need to give the value [2] along with the Xpath
as below
(Xpath) [2]

Interview Question :
How can you select the element from dynamic dropdown without using its index ?
Ans: Using the Parent – child combo
That is, Identify the Parent xpath space child xpath (which is the actual xpath)
For Example,
Chennai is available in both [From] and [To]. If u want to select the Chennai of [To]
dropdown, identify the xpath of [To] give space again identify the Xpath of Chennai.
e.g. Xpath of [To] is
//div[@id='glsctl00_mainContent_ddl_destinationStation1_CTNR'
Xpath of [Chennai] inside the [To] is //a[@value='MAA']"
Final Xpath will be
//div[@id='glsctl00_mainContent_ddl_destinationStation1_CTNR'Space
//a[@value='MAA']"

Auto Suggestive drop down


When we type letters, it will bring up the values in dropdowns

You might also like