18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Extracting all Elements in Array

NEWUSERNEWUSER Members
edited November -1 in Sahi - Open Source
In a page there are multiple textboxes with same name.
Sahi identify them by apending incremental index like:
Tb
Tb[1]
Tb[2]
How can i capture all textboxes in one array?
I have read artical http://www.w3schools.com/htmldom/dom_obj_form.asp but still i am confused that how to implement it in sahi.
Tagged:

Comments

  • Just to add into it. The elements which i am trying to capture are dynamic and are not coded directly in displayed HTML instead it is loaded dynamically by a JSP and are not viewable on the page source code.
  • dpdp Members
    Use document.forms[0].elements to get all elements in a form

    If you can access the elements by Tag or class, you can use document.getElementsByTag/ByClass etc

    Check if regular expression works for document.getElementsById
  • I have couple of dropdown lists present on the page. each dropdown have same name incrementing number appended. I have tried like this

    var $a = document.getElementsByName("seld_1");
    _alert(_getText($a));

    and it shows undefined. Am i going in right direction?
  • dpdp Members
    NEWUSER,

    document.getElementsByName returns an array of objects. Hence you need to use something like $a[0] to access the first element that is returned. So, in your code if you change the second line to
    _alert(_getText($a[0])); 
    
    it should properly display the content

    Since you are trying to access drop down boxes, you could use
    document.getElementsByTagName("SELECT") 
    
    to get an array of objects and then that can be manipulated as discussed above
  • I have tried below code
    var $a = document.getElementsByTagName("SELECT");
    _alert($a.length);

    It returns 0 while more than one dropdown list is present on page. I am also posting properties of one of the dropdown list which i have taken with sahi object spy

    scrollHeight=22;
    currentStyle={{[object]}};
    currentStyle=[object];
    document={{[object]}};
    document=[object];
    isMultiLine=true;
    clientHeight=22;
    parentTextEdit={{[object]}};
    parentTextEdit=[object];
    clientWidth=49;
    parentElement=[object];
    scopeName=HTML;
    outerText= NoYes;
    innerText= NoYes;
    tagName=SELECT;
    offsetWidth=49;
    contentEditable=inherit;
    runtimeStyle={{[object]}};
    runtimeStyle=[object];
    filters={{[object]}};
    filters=[object];
    offsetLeft=1;
    style={{[object]}};
    style=[object];
    canHaveChildren=true;
    behaviorUrns={{[object]}};
    behaviorUrns=[object];
    readyState=complete;
    all={{[object]}};
    all=[object];
    sourceIndex=416;
    outerHTML=<SELECT onchange="Functionncalling()" size=1 name=selStrapUsed_2> <OPTION value=NO>No</OPTION><OPTION value=YES selected>Yes</OPTION></SELECT>;
    innerHTML= <OPTION value=NO>No</OPTION><OPTION value=YES selected>Yes</OPTION>;
    offsetHeight=22;
    scrollWidth=49;
    offsetTop=1;
    offsetParent=[object];
    children={{[object]}};
    children=[object];
    firstChild={{[object]}};
    firstChild=[object];
    value=YES;
    length=2;
    lastChild={{[object]}};
    lastChild=[object];
    ownerDocument={{[object]}};
    ownerDocument=[object];
    nodeName=SELECT;
    attributes={{[object]}};
    attributes=[object];
    parentNode=[object];
    nodeType=1;
    form={{[object]}};
    form=[object];
    childNodes={{[object]}};
    childNodes=[object];
    size=1;
    type=select-one;
    name=selStrapUsed_2;
    selectedIndex=1;
    0={{[object]}};
    0=[object];
    1={{[object]}};
    1=[object];


    Functions

    onchange
  • narayannarayan Administrators
    document.getElementsByTagName("SELECT") is dependent on the DOM. You will have to evaluate it in the browser

    Do
    var $selectCount;
    _set($selectCount, document.getElementsByTagName("SELECT").length);
    _alert($selectCount);
    
Sign In or Register to comment.