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')]