Friday, January 9, 2009

Code to Identify an element on the basis of it's any dom attribute and index

use firebug to identify the attributes and their values



function getLocator(elementClassName,attributeName,attribtePtrn,elemIndex){

var allInputArray = new Array();
var requiredElement;
allInputArray=document.getElementsByTagName(elementClassName);
var i=0;
var index=0;
var requiredIndex=elemIndex;

var pattrn=new RegExp("^"+attribtePtrn+"$");

for(i=0; i
if (pattrn.test(allInputArray[i].getAttribute(attributeName))){
if (index==requiredIndex){
requiredElement=allInputArray[i];
break;}
index=index+1;
}

}

return requiredElement;
}

//function call
getLocator("input","id","[a-c]{1}al00_mc_Chec.*",16);

1 Comment:

Shruti Ramalingam said...

Thanks for the great information in your blog Selenium Training in Chennai