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