Posts Tagged ‘selenium’

Get current page URL webdriver 2.0

Get the URL of the current page


Categories: Selenium Tags: , ,

Elements Locators in Selenium Ruby webdriver

September 24, 2012 2 comments
        :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
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


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;


Categories: Selenium Tags: ,

Selenium Webdriver with Ruby Unit Example of Google Search

Copy the code and save as google_search.rb and run “ruby google_search.rb”

require “selenium-webdriver”
require “test/unit”
class GoogleSearch < Test::Unit::TestCase
  def setup
    @driver = Selenium::WebDriver.for :firefox
    @base_url = “;
    @driver.manage.timeouts.implicit_wait = 30
    @verification_errors = []
  def teardown
    assert_equal [], @verification_errors
  def test_google_search
    @driver.find_element(:name, “q”).clear
    @driver.find_element(:name, “q”).send_keys “Thiyagarajan Veluchamy”
    @driver.find_element(:name, “btnK”).click
  def element_present?(how, what)
    @driver.find_element(how, what)
  rescue Selenium::WebDriver::Error::NoSuchElementError
  def verify(&blk)
  rescue Test::Unit::AssertionFailedError => ex
    @verification_errors << ex
Categories: Uncategorized 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;

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: ,

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

For the example,

<a target=”_blank” id=”verify_email” href=”″>Verify your email</a>

So We can use following,

<td>echo</td> ‘ this is only optional to see the link


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: ,

Locating Elements in Selenium IDE

Locating by Id

Locating by Name

Locating by XPath

Locating Hyperlinks by Link Text

Locating by DOM

Locating by CSS

Categories: Selenium Tags:

write the selenium IDE test case for CAPTCHA images

Try prompt a text box for user to key in the captcha, and store in variable


storeEval | prompt(“Enter Captcha:”) | varName

Then type the varName text in to your captcha text box example

type | id=CaptchaText | ${varName}

Categories: Selenium Tags: ,

Object Identification In Selenium

The following Identifiers used for object identification,

  1. id
  2. name
  3. dom
  4. xpath
  5. link
  6. css

handle autocomplete in selenium IDE

The type command may not be enough to trigger the autocomplete.  My only addition would be that you might need the typeKeys command, which causes slightly different JavaScript events to be fired, which may be more likely to trigger the autocomplete widget.

So we can use the following steps to handle the situation,

  • typeKeys
  • waitForTextPresent
  • mouseOver
  • clickAt
Categories: Selenium Tags: , ,