Automation: Sahi “_collect”

Excerpt from Sahi Support Forum

SEARCHING SAHI for an example of returning a collection or array

by “getElementsByID”, “getElementByName” or “getElementsByClass??

I do this regularly with VBS and QTP, but hit a big big speed-bump trying to convert those scripts to Sahi.

For instance:
Say you want to click on each of 20-500 closed nodes in different folder “trees” identified/marked by

<div class=abc id=img01n4><img src="plus.gif" title="xyz"/>definition of xyz</div>

Simply recording this in Sahi only gives 20-500 lines with every explicit ID – useless for varying node structures, without some glob or regex pattern of ID to return an array? I thought surely this has already been documented – but didn’t see any of the “getelement” functions in the Sahi Forums.

Finally found A CLUE, deep inside the demo folder of “_collect” which led to a solution of sorts below.

(I call the function 2-3 times, one for each of two nested levels.
A clone of the function handles a single node identified by DIV rather than SPAN.

I failed to open the topmost of each inner/second level node UNTIL I ran the loop “backwards” from top to bottom. You may want to experiment with “for(x=n;x

openNodes(); // first pass

openNodes(); // second / inner set of nodes

openDivNodes(); // one lonely stubborn node

openNodes(); // the last hold outs (the zero-th) inner / second level nodes

// functions below

function openNodes() {
var $plusgifs = _collect (“_image”, “/plus.gif/”, _in(_image(“image”))); //
_set($Count, $plusgifs.length);
for (var $i = $Count – 1; $i > 0 ; $i–)
// full example on Sahi forum

This entry was posted in Automation, Scripts and tagged , , , . Bookmark the permalink.