Archive

Archive for the ‘Selenium’ Category

Get current page URL webdriver 2.0

Get the URL of the current page

@driver.current_url

Categories: Selenium Tags: , ,

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’
Categories: Selenium Tags: , ,

get number of links in a page using Selenium IDE

get number of links in a page using Selenium IDE
<tr>
<td>open</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>window.document.getElementsByTagName(&quot;a&quot;).length</td>
<td>totallinks</td>
</tr>
<tr>
<td>echo</td>
<td>${totallinks}</td>
<td></td>
</tr>
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: ,

Generate random email id in Ruby

Guys,

We can return random email using following method

def email
      emailid = (0..8).map{(‘a’..’z’).to_a[rand(26)]}.join+”@yopmail.com”
      return emailid
end
while need random email id, just call the method “email()”.
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: ,