Automation Using Selenium Webdriver

Sunday 13 November 2016

Collections List

List Interface:
List allows Duplicate Elements.
List having index.
List allows n number of null values.
List will display Insertion order with index.
List having classes like :
Vector
ArrayList
LinkedList
Vector:
Vector is a legacy class.
Vector is synchronized.
Vector initial capacity is 10.
Vector allows n number of null values
Vector can be accessible by index.
Vector allows Duplicate Elements.
Program for Vector:

package com.instanceofjavaforus;
import java.util.Enumeration;

import java.util.List;

import java.util.Vector;



public class A{

 public static void main(String[] args) {

 

 Vector vector=new Vector();



 vector.add("india");

 vector.add("jagan");

 vector.add("sam");

 vector.addElement(null);

 vector.addElement(null);
 
  Enumeration em=vector.elements();
 while(em.hasMoreElements()){
  System.out.println(em.nextElement());
 
 }
 }

}
Output:

india
jagan
sam
null

null



ArrayList:

ArrayList is not Synchronized.
Arraylist also allows Duplicate Elements.
ArrayList allows n number of null values.
Arraylist  having insertion order with index.
For retrieve purpose ArrayList is best choice.
ArrayList having Randaom Access Nature.
Program for ArrayList ;



package com.instanceofjava;
import java.util.ArrayList;
import java.util.ListIterator;

import java.util.List;



public class A{

 public static void main(String[] args) {

 

             ArrayList arrayList=new ArrayList();




 arrayList.add("jagan");

 arrayList.add("jagan");

 arrayList.add("upendra");

 arrayList.add(null);

 arrayList.add(null);
 
  ListIterator it=arrayList.listIterator();
 while(it.hasNext()){
  System.out.println(it.hasNext());
 
 }
 }
}

Output:
jagan
jagan
upendra
null
null

LinkedList:

LinkedList is not synchronized.
LinkedList allows n number of null values.
LinkedList allows Duplicate Elements.
LinkedList  having insertion order with index.
Insertion and Deletion purpose LinkedList is better choice.
LinkedList Follows Doubly linked list Structure.
Program for LinkedList:


package com.instanceofjava;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.List;

public class A{

 public static void main(String[] args) {

   LinkedList linkedList=new LinkedList();




 linkedList.add("jagan");

 linkedList.add("jagan");

 linkedList.add("naresh");

 linkedList.add(null);

 linkedList.add(null);


  ListIterator it=linkedList.listIterator();
  while(it.hasNext()){
  System.out.println(it.hasNext());
 
 }
 }
}

Output:


jagan
jagan
naresh
null
null
In List interface if you want  to add elements we can use add() method.
If you want  to remove elements we can use remove() method.

Using Keys Method to Perform Keyboard Actions in Suggestions List Box

There’s always a need to perform keyboard actions in Suggestion List.For that purpose we  can use this ‘org.openqa.selenium.Keys’ method. Here I am sharing the Code, how to do it.
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class indianrail
{
public static void main(String[] args) throws Exception
{
FirefoxDriver fd=new FirefoxDriver();
fd.get(“http://www.indianrail.gov.in”);
fd.findElement(By.linkText(“Trains between Stations”)).click();
Thread.sleep(5000);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(“hyd”);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationFrom”)).sendKeys(Keys.ENTER);
Thread.sleep(2000);
fd.findElement(By.id(“txtStationTo”)).sendKeys(“bangalo”);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ARROW_DOWN);
fd.findElement(By.id(“txtStationTo”)).sendKeys(Keys.ENTER);
Thread.sleep(2000);
new Select(fd.findElement(By.name(“lccp_classopt”))).selectByVisibleText(“THIRD AC”);
Thread.sleep(2000);
fd.findElement(By.name(“submit2”)).click();
}
}