Automation Using Selenium Webdriver

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());

}

}

}