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

Hierarchical inheritance example:

Class 1:
package hierarchial_inheritance;

import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriv
er;

public class Opening {


WebDriver d;
String url="http://www.amazon.in";
public void Opening_Page()
{

System.setProperty("webdriver.chrome.
driver","D://chromedriver.exe");
d=new ChromeDriver();
d.get(url);
d.manage().window().maximize();
}
public void title()
{
System.out.println("page
title :"+d.getTitle());
}
Class :

package hierarchial_inheritance;

import java.util.List;

import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;

public class Searching extends


Opening{
public void url()
{
System.out.println("page
url:"+d.getCurrentUrl());
}
public void Search()
{
d.findElement(By.id("searchDropdownBo
x")).sendKeys("Books");
d.findElement(By.id("twotabsearchtext
box")).sendKeys("harryporter");
d.findElement(By.id("nav-search-
submit-button")).click();
}

Class 3:
package hierarchial_inheritance;

import java.util.List;

import org.openqa.selenium.By;
import
org.openqa.selenium.WebElement;

public class Counting extends


Opening{
public void Count()
{
WebElement
drop=d.findElement(By.id("searchDropd
ownBox"));
List<WebElement>drop1=drop.findElemen
ts(By.tagName("option"));
System.out.println(drop1.size());
for(int i=0;i<drop1.size();i++)
{

System.out.println(drop1.get(i).getTe
xt());
}
}
public void Screenshot()

{
System.out.println("captured
screenshot sucessfully");
}

Class 4:
package hierarchial_inheritance;

public class Calling extends Opening{


public void close()
{
d.close();
}

public static void main(String[]


args) {
// TODO Auto-generated method
stub

Calling a1=new Calling();


a1.Opening_Page();
a1.close();
a1.title();

Searching b1=new Searching();


b1.Search();
b1.url();
Counting c1=new Counting();
c1.Count();

}
Multiple inheritance :

class 1:
interface addition
{
Void add()
}
Class subtraction
{
Void sub()
{
int x,y=20,z=30;
z=y-z;
S.o.p();
}
class mul extends subtraction
implements addition
{
Public void add()
{
Int x, y=20,z=40;
X=y+z;
S.o.p(x);
}
Void mul()
{
int x,y=20,z=40;
X=y*z;
S.o.p(x);
}

Public static void main(String[]


args)
{
Mul a1= mul();
A1.add();
A1.sub();
A1.mul():

You might also like