Monday, 13 October 2014

Co-relation in TRUclient Ajax Load Runner



When you want to randomly select an option from the list (i.e an option from <select> tag), TRUclient automatically records it as select statement and you just need to set Ordinal value to 0(random), 1(First occurrence)....etc

But, when you want to randomly extract inner-html of  SPAN/Div elements use below code

Step 1: Insert a Evaluate JavaScript component from tool box after the step from whose response you want extract innerHTML




Step 2:  Insert below code into Argument section of Evaluate JavaScript Component




var x = document.querySelectorAll("Span[id^=\"agcDiscountType_Row\"]"); //Storing all span elements with "id" starting with "agcDiscountType_Row" in X;
var index = Math.floor((Math.random()*(x.length))+1);  //Selecting a random number from total number of Span elements
var req = document.querySelector("Span[id=\"agcDiscountType_Row"+index.toString()+"\"]"); //Selecting a random Span element
window.alert("Span[id=\"agcDiscountType_Row"+index+"\"]"); 
var value = req.innerHTML; //Extracting innerHTML of randomly selected Span Element
window.alert(value); 

No comments:

Post a Comment