Thursday, June 23, 2011

Selenium - How to find string exists in the browser url or not ??





/**********************************************************
     Function Name      : LocationTextPresent
     Arguments             : text
     Description             : This function checks whether text is present in URL or not.
     Author                    : Sara ,Bangalore
/*********************************************************/
Selenium.prototype.getLocationTextPresent = function(text) {

     var element = this.browserbot.getCurrentWindow().location;

             var patternMatcher = new PatternMatcher(text);
    if (patternMatcher.strategy == PatternMatcher.strategies.glob) {
            if (text.indexOf("glob:")==0) {
                    text = text.substring("glob:".length); // strip off "glob:"
                }
        patternMatcher.matcher = new PatternMatcher.strategies.globContains(text);
    }
    else if (patternMatcher.strategy == PatternMatcher.strategies.exact) {
                text = text.substring("exact:".length); // strip off "exact:"
        return element.indexOf(text) != -1;
    }
    return patternMatcher.matches(element);
};

<tr>
            <td>verifyLocationTextPresent</td>
            <td>ruby</td>
            <td>true</td>
</tr>

Ex: 


<tr>
            <td>verifyLocationTextPresent</td>
            <td>sara</td>
            <td>true</td>
</tr>

No comments:

Post a Comment