Archive

Posts Tagged ‘selenium ide’

Elements Locators in Selenium Ruby webdriver

        :class             => ‘class name’,
        :class_name        => ‘class name’,
        :css               => ‘css selector’,
        :id                => ‘id’,
        :link              => ‘link text’,
        :link_text         => ‘link text’,
        :name              => ‘name’,
        :partial_link_text => ‘partial link text’,
        :tag_name          => ‘tag name’,
        :xpath             => ‘xpath’
Advertisements
Categories: Selenium Tags: , ,

round off the decimal value to decimal places using Selenium IDE

round off the decimal value to decimal places using Selenium IDE

Input:-

<tr>
<td>roundUp</td>
<td>23.33345555,4</td>
<td>aa</td>
</tr>
script:-
Selenium.prototype.doRoundUp = function(elementOne, elementTwo)
{
 var val = elementOne.split(‘,’);
 var value = val[0];
 var digits = val[1];
 var numberRounded = (Math.round((value*Math.pow(10,digits)).toFixed(digits-1))/Math.pow(10,digits)).toFixed(digits);
 storedVars[ elementTwo ] = numberRounded;
};
Output:-
23.3335

 

Categories: Selenium Tags: ,

get tomorrow’s Date using javascript for selenium IDE

Selenium.prototype.doGenerateTomorrowDate = function( varName1, varName2 ) 
{
    var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
    var day = currentDate.getDate()
    var month = currentDate.getMonth() + 1
    var year = currentDate.getFullYear()
    var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
    var month = monthNames[month];
    storedVars[ varName1 ] =  day;
    storedVars[ varName2 ] =  month;
};

<tr>
    <td>generateTomorrowDate</td>
    <td>x</td>
    <td>y</td>
</tr>
<tr>
    <td>echo</td>
    <td>${x}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${y}</td>
    <td></td>
</tr>
Categories: Selenium Tags: ,

if statement in Selenium IDE

open  | URL of site
storeTextPresent  | any unique text of page a  | title
gotoIf  | storedVars.title  | true
getEval | alert(“page B”);
gotolabel | finish
label  | true
getEval | alert(“Page A”);
label | finish

This will check whether title is present or not, and if present control will redirect to label true, else will execute next statement after gotoif.

Categories: Selenium Tags: ,

Get id of div from its class name using JavaScript for Selenium IDE

Get id of div from its class name using JavaScript for Selenium IDE
<tr>
<td>storeEval</td>
<td>window.document.getElementsByClassName(‘classname’)[0].id</td>
<td>idname</td>
</tr>
<tr>
<td>echo</td>
<td>${idname}</td>
<td></td>
</tr>
Categories: Selenium Tags:

How to solve the link has target ‘_blank’, which is not supported in Selenium

For the example,

<a target=”_blank” id=”verify_email” href=”https://thiyagarajan.wordpress.com/users/verify/1341484215″>Verify your email</a>

So We can use following,

<tr>
<td>storeAttribute</td>
<td>//a[@id=’verify_email’]/@href</td>
<td>href</td>
</tr>
<tr>
<td>echo</td> ‘ this is only optional to see the link
<td>${href}</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${href}</td>
<td></td>
</tr>

 

Categories: Selenium Tags: ,

Generates a random word using JavaScript in Selenium IDE

Selenium.prototype.doRandomWord = function( length, varName ) {
    var consonants = ‘bcdfghjklmnpqrstvwxyz’,
        vowels = ‘aeiou’,
        rand = function(limit) {
            return Math.floor(Math.random()*limit);
        },
        i, word=”, length = parseInt(length,10),
        consonants = consonants.split(”),
        vowels = vowels.split(”);
    for (i=0;i<length/2;i++) {
        var randConsonant = consonants[rand(consonants.length)],
            randVowel = vowels[rand(vowels.length)];
        word += (i===0) ? randConsonant.toUpperCase() : randConsonant;
        word += i*2<length-1 ? randVowel : ”;
    }
storedVars[ varName ] =  word;
};
Categories: Selenium Tags: ,