Wednesday, 9 January 2019

How to navigate to last page using pagination

ow to navigate to last page using pagination
Steps:
1) First get the total 'pagination text'
2) Now split at last page number(depends upon req)
 String lastPageNumber = driver.paginationInfo.split(" ")[2];
3) Now get current URL
 String currentUrl = driver.getCurrentUrl();
4) now take the length of current URL
int urlLength = currentUrl.length();
5) add page number on url(if you want remove something in current URL use subsctring)
String lastPageUrl = currentUrl+lastPageNumber;
String lastPageUrl = currentUrl.substring(0, urlLength - 1) + lastPageNumber; (sub string)
        driver.get(lastPageUrl);

How to remove special charterer from URL using URLdecoder

How to remove special chartector from URL using URLdecoder
Method for decode URL:
 public String decodeParameter(String param) {
        try {
            return URLDecoder.decode(param, "UTF-8");
        } catch (Exception e) {
            return URLDecoder.decode(param);
        }
    }

- - Call above method to test
ex-
newUrl = driver.getCurrentUrl().
            decodedURL=decodeParameter(curr);

Append query string to URL with simple way

Append query string to URL with simple way
Step 1 : Need to get current URL and your query string
String currentUrl = driver.getCurrentUrl()+String;
Sample method:

 public void addString(String query) {
        String newURL = driver.getCurrentUrl()+query;
        driver.get(newURL);
    }

Append query string to current URL with single parameter or only with key -way 2

Append query string to current URL with single parameter or only with key -way 2
Step 1 : Need to get current URL
String currentUrl = driver.getCurrentUrl();
Step2: Take new string to store value
 String newUrl = null;
Step3:
Add parameters to URI builder class
try {
            newUrl = new URIBuilder(currentUrl).addParameter(key/parameter, null).toString();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
  driver.get(newUrl);

Append query string to current URL with key value pair - way 1

Append query string to current URL with key value pair - way 1
Step 1 : Need to get current URL
String currentUrl = driver.getCurrentUrl();
Step2: use URI buider class to add parameters
Steps3: Split your string as key and value pair
Ex- string abcd=def then here, key is 'abcd', value is 'def'
Step4: Add current url, key and value to URI builder class
ex -  driver.get(new URIBuilder(currentUrl).addParameter(key, value).toString());

Thursday, 14 December 2017

How to find css slector in Chrome browser

How to find css slector in Chrome browser
Steps:
1) Load the URL in chrome browser
2) Right click on mouse and select inspect option
3) Select inspect option in tool bar (first option (has arrow symbol))
4) Now select which filed locator you want
5) It highlights html code with blue color
6) We dont see css selector in right click options
7) See below hight lighted (below tool bar)
8) Mouse hiover on each and observe highted in page
9)  capy hightted code and paste in your selenium code
10) Works fine
ex - facebook email filed ()

Regular expresstion for locators (css selector)

Regular expresstion for locators (css selector)
it can be used when values are keep changing
ex - username1,username2 etx...
Note: Keep contstant word a side
syntax - tagName[Attribute*='value')]
ex - input[name*='username')]

Regular expresstion for locators (xpath)

Regular expresstion for locators (xpath)
it can be used when values are keep changing
ex - username1,username2 etx...
Note: Keep contstant word a side
syntax - //tagName[contains(@attribute,'value')]
ex - //input[contains(@name,'username')]

Different ways to write css selector

Different ways to write css selector
css selector syntax -
1)  tagName[attribute='value']
2) tagName#id (input#username)
3) tagname.classname

Different ways to write xpath

way 1:
Xpath syntax 1 - //tagName[@attribute='value']
way 1 - driver.findElement(By.xpath("//input[@id='email']")).sendKeys("hello");
way 2:
Xpath syntax 2 - //*[@attribute='value']
way 2 - driver.findElement(By.xpath("//*[@id='email']")).sendKeys("hello");

Note : here, * represents tagName (* verifies directly where //*[@id='email'])

How to validate xPath (whether the written xpath exist in page or name)

How to validate xPath (whether the written xpath exist in page or name)
Steps:
1) Load the URL in chrome browser
2) Right click on mouse and select inspect option
3) Select inspect option in tool bar (first option (has arrow symbol))
4) Now select which filed locator you want
5) It highlights html code with blue color
6) Right click on high lighted line
7) select Copy
8) select copy xpath
9) Go to console tab
xpath validation - $x ($x("//*[@id='pass']"))
css validation - $ ($("#loginbutton"))

How to find xPath in Chrome browser

How to find xPath in Chrome browser
Steps:
1) Load the URL in chrome browser
2) Right click on mouse and select inspect option
3) Select inspect option in tool bar (first option (has arrow symbol))
4) Now select which filed locator you want
5) It highlights html code with blue color
6) Right click on high lighted line
7) select Copy
8) select copy xpath
9) paste in your selenium code
10) Works fine
ex- facebook email filed (//*[@id="email"])

Thursday, 27 October 2016

How to get uniq value from array

package java_practice;

import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;

public class Uniqvaluesfromarray {

public static void main(String[] args) {
// TODO Auto-generated method stub
Integer[] numbers = {1, 1, 2, 1, 3, 4, 5};
Set<Integer> uniqKeys = new TreeSet<Integer>();
uniqKeys.addAll(Arrays.asList(numbers));
System.out.println("uniqKeys: " + uniqKeys);
}

}


Output: uniqKeys: [1, 2, 3, 4, 5]

Thursday, 16 June 2016

Collections in java

Java Collections:
Collection: Collection represents a single unit of object/group.
Java Collections framework is collection of interfaces and classes which helps in storing and procesing data efficiently.

                        Collection(interface)
Set(interface)                        List(interface)                Queue(interface)
Hashset,LinkedHashSet,Treeset(sortedSet)        ArrayList,Vector,LinkedList        LinkedList,PriorityQueue

1) List:
List is an ordered collection(sequence).
List may contains duplicate elements
List index is starts with Zero

1a) ArrayList:
ArrayList is resizable implemented from List interface
Java ArrayList class can contain duplicate elements.
ArrayList class maintain insertion order.
ArrayList class is non synchronized.

Methods of ArrayList class:

add("String")
add(index, "String")
remove("String")
set(int index,Object)
indexOf(Object)
get(int index)
size()
contains("String")
clear()



Sample code using ArrayList:


package collections;

import java.util.ArrayList;

public class ArrayList_Example {

    public static void main(String[] args) {
        ArrayList<String> arr=new ArrayList<String>();
        arr.add("padi");
        arr.add("pravanjan");
        arr.add("reddy");
        System.out.println("printing arrayList: " + arr);
        System.out.println("Printing size of array:" + arr.size());
        System.out.println("Element at index 0 :" + arr.get(0));
        System.out.println("Does arrayList contains padi: "+arr.contains("padi"));
        arr.add(2, "REDDDY");
        System.out.println("printing arrayList: " + arr);
        System.out.println("Index of PERL is "+arr.indexOf("reddy"));
        System.out.println("Printing size of array:" + arr.size());
       
    }
}

Output:
printing arrayList: [padi, pravanjan, reddy]
Printing size of array:3
Element at index 0 :padi
Does arrayList contains padi: true
printing arrayList: [padi, pravanjan, REDDDY, reddy]
Index of PERL is 3
Printing size of array:4

1b) LinkedList:
Java v class uses doublly linked list to store the elements
LinkedList class can contain duplicate elements
LinkedList class maintains insertion order
LinkedList is non synchronized

Sample Code:
package collections;

import java.util.LinkedList;
import java.util.*;

public class LinkedList_Example {
   
    public static void main(String[] args) {
       
   
    LinkedList<String> ll=new LinkedList<String>();
    ll.add("pabbu");
    ll.add("reddy");
    ll.add("aaaaaaaaaa");
    System.out.println("Printin all linked list values : " + ll);
    Iterator<String> itr=ll.iterator();
    while (itr.hasNext()) {
    System.out.println("printing values using iterator :" + itr.next());
       
    }
    }
}

Output:
Printin all linked list values : [pabbu, reddy, aaaaaaaaaa]
printing values using iterator :pabbu
printing values using iterator :reddy
printing values using iterator :aaaaaaaaaa

+++++++++++++++++ Hash Set Class++++++++++++++
HashSet class uses hashtable to store the elements, It extends AbstartctSet class implements Set interface
HashSet contains only unique elemets.
HashSet contains only Values
 Difference between List and Set:
 - List can contains duplicate elements whereas Set contains unique elemenets only.

++++++++++ Sample code using HashSet class +++++++++
package collections;

import java.util.HashSet;
import java.util.Iterator;

public class HashSet_Example {
public static void main(String[] args) {
    HashSet<String> hset=new HashSet<String>();
    hset.add("pabbu");
    hset.add("pabbu");
    hset.add("reddy");
    hset.add("abcd");
    System.out.println("Printin all values from HaseSet: " + hset);
    Iterator<String> itr=hset.iterator();
    while (itr.hasNext()) {
    System.out.println("printin vaue using iterator : " + itr.next());
       
    }
   
}
}

Output :
Printin all values from HaseSet: [pabbu, reddy, abcd]
printin vaue using iterator : pabbu
printin vaue using iterator : reddy
printin vaue using iterator : abcd

++++++++++++++++ Tree Set Class ++++++++++
- Contains uniqe elements like HashSet
 - Maintains ascending order

Sample code for TreeSet :

package collections;

import java.util.Iterator;
import java.util.TreeSet;

public class TreeSet_Example {
public static void main(String[] args) {
    TreeSet<String> ts=new TreeSet<String>();
    ts.add("pabbu");
    ts.add("abcd");
    ts.add("reddy");
    ts.add("reddy");
    System.out.println(" Printin all values from TreeSet: " + ts);
    Iterator<String> itr=ts.iterator();
    while(itr.hasNext())
    {
        System.out.println("printin all values using iterator :" + itr.next());
    }
   
   
}
}

Output :
 Printin all values from TreeSet: [abcd, pabbu, reddy]
printin all values using iterator :abcd
printin all values using iterator :pabbu
printin all values using iterator :reddy

+++++++++++++    HashMap               +++++++++++
 - HashMap contains values based on the key. It implements the Map interface and extends the AbstractMap class.
 - It contains only Uniq elements
 - It may have one null key and multiple null values.
 - It maintains no order.

Sample code for HashMap:
package collections;
import java.util.*;
import java.util.HashMap;
import java.util.Map;


public class HashMapTest {
    public static void main(String[] args) {
       
   
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put(100,"pabbu");
hm.put(200, "reddy");
hm.put(200, "reddy");

    for(HashMap.Entry m:hm.entrySet())
    {
        System.out.println(m.getKey() + " "+m.getValue());
       
    }
   
    }
}


Output:

100 pabbu
200 reddy

+++++++++++++++
What is difference between HashSet and HashMap?

HashSet contains only values whereas HashMap contains entry(key and value).

++++++    Hash Table    ++++++++++++++
- HashTable is an array of list. Each list is know as bucket. The position of bucket is identified by calling the hascode() method.
- HashTable contains values based on the Key.
- it contains only Uniq elements.
- It may not have any null key or value.
- It is Synchronized

Sample Code for HashTable:
package collections;

import java.util.Hashtable;
import java.util.Map;

public class HashTable_Test {
    public static void main(String[] args) {
        Hashtable<Integer,String> ht=new Hashtable<Integer,String>();
        ht.put(100,"pabbu");
        ht.put(200, "reddy");
        ht.put(300,"pabbu");
        ht.put(100,"abcd");
        ht.put(400," ");
       
       
        for(Map.Entry m:ht.entrySet())
                {
            System.out.println(m.getKey()+" "+m.getValue());
                }
    }

}

Output:
400 
300 pabbu
200 reddy
100 abcd


++++++++++     Diffrence between HashMap and Hashtable     ++++

    HashMap                                Hashtable
1) HashMap is non synchronized. It is not thread safe.        1) Hashtable is synchronized.It is thread safe and can be shaed with manu threads.
2) HashMap allows one null key and multiple null values        2) Hashtable doesnt allow any null key or value
3) HashMap is a new class introduced in JDK 1.2            3) Hashtable is legacy class
4) HashMap is fast                        4) hASHTABLE is slow
5) We can make HashMap as synchronized by calling
   Map m=Collections.synchronizedMap(hashMap)            5) Hashtable is internally syncronized






Sorting in assending order using java

package java_interview;

public class Sort_AssendingOrder {
    public static void main(String[] args) {

        int[] arr={22,33,11,31,34};
        int t=0;
        for(int i=0;i<arr.length;i++){
        for(int j=i+1;j<arr.length;j++){
        if(arr[i]>arr[j]){
        t=arr[i];
        arr[i]=arr[j];
        arr[j]=t;

        }
        }
        }

        for(int k=0;k<arr.length;k++){
        System.out.println(arr[k]);
        }
    }
}
Output:
11
22
31
33
34

How to get repeated string in java

package java_interview;

public class RepetedStringCount {
    public static void main(String[] args) {

        String s="regression";
        int repeated;

        for(int i=0;i<s.length();i++)
        {
        for(int j=i+1;j<s.length();j++)
        {
        if(i!=j && s.charAt(i)==s.charAt(j)){
        System.out.println(s.charAt(i));
        break;
        }
        }
        }}
}

Output:
r
e
s

Wednesday, 15 June 2016

How to print minimum number and maximum number in java


public class Print_Min_Max_Value {
   

public static void main(String[] args)
{
    int i;  //loop counter
    int[] arr=new int[]{10,20,90,50}; //arrays
    int min=arr[0]; //set values for comparison from start to end of the array
    int max=arr[0]; //set values for comparison from start to end of the array
    for (i=0;i<arr.length;i++)
    {
        if(arr[i]>max)
        {
            max=arr[i];
        }
        else if(arr[i]<min)
        {
            min=arr[i];
        }
    }
    System.out.println(max);
    System.out.println(min);
   
}




}
output:
90
10

How to check whether the given number is prime number or not


public class PrimeNumber_Or_Not {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
int x;
{
    for(x=2;x<=10;x++)
        if(x%2==0)
        {
            System.out.println("not prime" + x);
           
        }
    else {
        System.out.println("prime " + x);
    }
}
    }

   
   
}
Output:
not prime2
prime 3
not prime4
prime 5
not prime6
prime 7
not prime8
prime 9
not prime10

fibonacci example program


public class Fibonacy {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
int a=0;
int b=1;
for(int i=0;i<10;i++)
{
   
    a=a+b;
    //System.out.println("a data"+a);
    b=a-b;
    System.out.println("b data "+b);
}
    }

}

Output:
b data 0
b data 1
b data 1
b data 2
b data 3
b data 5
b data 8
b data 13
b data 21
b data 34

Handling popups using AutoIt