Automation Using Selenium Webdriver

Saturday, 30 July 2016

Simple and Easy Example for Java - Polymorphism

polymorphism :--
--------------------
polymorphism mean exiting objects behaviour in many forms

There are two type of polymorphism
signature  1)No of orgumantes 2)Types of orguments 3)order of arguments

In below program we have three print methods each with different arguments. When you properly overload a method, you can call it providing different argument lists, and the appropriate version of the method executes

1)complile time / static /method overloading:
-----------------------------------------------------

    Example
   -------------
         public class MethodOverload {


public void add(int a, int b){
System.out.println(a+b);
}
public void add(int a, int b, int c){
System.out.println(a+b+c);
}
public void add(double a,double b, double c){
System.out.println(a+b+c);
}

public static void main(String[] args) {
MethodOverload mo=new MethodOverload();
mo.add(10, 20);
mo.add(20, 30, 50);
        mo.add(1.245, 4.567, 7.890);
}

}

2)Run time polymorphism:-
---------------------------------
    If two are more methods haveing same name and same arguments available in the  super class and sub class

        Example:
        -----------

public class A {
public void addition(int a,int b){
System.out.println(a+b);


}
public static void main(String[]args){
A ja=new A();
ja.addition(20, 50);
}

}

public class B extends A{
public void addition(int a,int b){
System.out.println(a+b);

}


public static void main(String[] args) {
A ja1=new A();
ja1.addition(40, 30);//70
B ja2=new B();
ja1.addition(55, 35);//90
}

}


Friday, 29 July 2016

Check Box

Check Box in Webpage Checked or not

package com.Test.web;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class CheckBox {

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.irctc.co.in");
driver.manage().window().maximize();
if (!driver.findElement(By.id("otpId")).isSelected());
{
driver.findElement(By.id("otpId")).click();
}


}

}

Java Program Palindrom


Given Number palindrome Or not

Palindrome number in Java: A palindrome number is a number such that if we reverse it, it will not change. For example some palindrome numbers examples are 121, 212, 12321, -454. To check whether a number is palindrome or not first we reverse it and then compare the number obtained with the original, if both are same then number is palindrome otherwise not. C program for palindrome number is given below.

Example:

                package com.java.exmp;

public class Palindrom {

public static void main(String[] args) {
int r,sum=0,temp;
int n=57575;
        temp=n;
        while(n>0)
{
        r=n%10;
        sum=(sum*10)+r;
        n=n/10;
       
}
        if(temp==sum)
        System.out.println("Palindrom number");
        else
        System.out.println("Not Palindrom number");

}

}

Output:
Palindrom number

Get Links Titles On Web Page

package com.Test.web;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PrintCitesDropDown {
    static WebDriver driver;
public static void main(String[] args) throws Exception {
Thread.sleep(5000);
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// driver=new FirefoxDriver();
driver=new ChromeDriver();
driver.manage().window().maximize();
//Print DropDown list Cities
driver.get("https://www.goindigo.in/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/input[1]")).click();
List<WebElement>cities=driver.findElements(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/div/ul/li"));
System.out.println("Number of Links:"+cities.size());
for (int i = 0; i < cities.size(); i++) {
System.out.println(i+1+")city name:"+cities.get(i).getText());

}

}

}

How to get from dropdown list cities


package com.Test.web;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PrintCitesDropDown {
    static WebDriver driver;
public static void main(String[] args) throws Exception {
Thread.sleep(5000);
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// driver=new FirefoxDriver();
driver=new ChromeDriver();
driver.manage().window().maximize();
//Print DropDown list Cities
driver.get("https://www.goindigo.in/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/input[1]")).click();
List<WebElement>cities=driver.findElements(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/div/ul/li"));
System.out.println("Number of cities:"+cities.size());
for (int i = 0; i < cities.size(); i++) {
System.out.println(i+1+")city name:"+cities.get(i).getText());

}

}

}

How to get from dropdown list cities


package com.Test.web;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class PrintCitesDropDown {
    static WebDriver driver;
public static void main(String[] args) throws Exception {
Thread.sleep(5000);
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
// driver=new FirefoxDriver();
driver=new ChromeDriver();
driver.manage().window().maximize();
//Print DropDown list Cities
driver.get("https://www.goindigo.in/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/input[1]")).click();
List<WebElement>cities=driver.findElements(By.xpath(".//*[@id='roundWay']/form/ul/li[1]/div/ul/li"));
System.out.println("Number of cities:"+cities.size());
for (int i = 0; i < cities.size(); i++) {
System.out.println(i+1+")city name:"+cities.get(i).getText());

}

}

}