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.

get links of specific panel

sivasiva Members
edited November -1 in Sahi - Open Source
Dear All,

I am siva, i am having doubt regarding "document.links"

when we use document.links we will get all the links in that page
but if i wanna get a specific area links only it is not getting for me

if there is two panels in page, ie. left panel and right panel, if i wanna get only the links in left panel then how to write a syntax instead of document.links

kindly provide a syntax for this problem

Thanks in advance to all

Comments

  • globalwormingglobalworming Moderators
    Hi

    try to use the _collect API, example here
    it should work as _collect(elementType, name, _in(leftPanel))

    regards
    Wormi
  • sivasiva Members
    edited May 2011
    Dear Wormi,

    thanks a lot for your reply

    i am new to sahi, i am not getting how to use _collect(elementType, name, _in(leftPanel))

    to understand my problem please view this site
    http: // sdeportal.ct.gov/Cedar/WEB/ct_report/DTHome.aspx

    here we can see some links in left side like


    Average Class Size
    CAPT
    CMT
    Discipline

    this links are existing under "---_div("Menutagname1_TreeView1")---" div tag
    now if i use "---document.links---" i am getting all the links but i want only the links count and links data which is existing in left side under "---div tag---"

    i have tried like this way

    _div("Menutagname1_TreeView1").document.links
    and
    var $els = _collect("_link", _div("Menutagname1_TreeView1"));

    but it is displaying error

    the solution for this in QTP is like this way i have used, it will get only the links count and links data from that specific left side "---div tag---"

    QTP: --- Set Links_SubjectArea = Browser("micclass:=Browser").Page("micclass:=Page").WebElement("html id:=Menutagname1_TreeView1").ChildObjects(oDescLink)

    now i want the same way which i have shown above in QTP, i want in sahi

    please provide me the syntax in sahi to get the links under "---div tag---"

    Thanks in advance and thanks a lot for your reply

    Regards,
    Siva
  • globalwormingglobalworming Moderators
    hi siva


    _count("_link", "/./", _in(_div("Menutagname1_TreeView1")));
    will return 19, the number of links in the left sidebar
    var $allLinksCollected = _collect("_link", "/./", _in(_div("Menutagname1_TreeView1")));
    should store all link objekts in an array

    hope this helps

    Reagrds
    Wormi
  • sivasiva Members
    edited May 2011
    Dear Wormi,

    Awesome! this is working fine. thanks a lot

    but i got small problem with getting link name of that link object which is stored in array

    actually i need the link names to be used again and again when ever i required . so i have storing this values in array and try to retrieve again
    when i try to retrieve the array instead of giving link name it is giving

    _link("/./[0]", _in(_div("Menutagname1_TreeView1"))).text


    i use
    var $allLinksCollected = _collect("_link", "/./", _in(_div("Menutagname1_TreeView1")));
    $allLinksCollected[$i].text to get the link name


    i have written code like this

    var $allLinksCollected = _collect("_link", "/./", _in(_div("Menutagname1_TreeView1")));
    var $arry_SubjArea = [];
    $arry_SubjArea = $allLinksCollected;

    for(var $i=0; $i<$allLinksCollected.length; $i++){
    $arry_SubjArea[$i] = $allLinksCollected[$i].text;
    }

    for(var $i=0; $i<$arry_SubjArea.length; $i++){
    _debug("
    "+ $arry_SubjArea[$i] +"
    ");
    _alert("
    "+ $arry_SubjArea[$i] +"
    ");
    }


    please open the site and run the above code

    URL: http: // sdeportal.ct.gov/Cedar/WEB/ct_report/DTHome.aspx

    when i use to see the output of _alert(), it is displaying the link names in correct format
    Example: Average Class Size


    but when i use _debug() instead of _alert() it is not displaying as "--- Average class size---"
    it is displaying as "--- _link("/./[0]", _in(_div("Menutagname1_TreeView1"))).text ---"
    im not getting the link name when i use _debug()


    why this is displaying differently in _debug() and _alert()
    when i use _alert() it is displaying correctly with link name
    but
    when i use _debug() it is not displaying correctly with link name

    Thank you very much for your help

    Regards,
    Sivakumar S
  • globalwormingglobalworming Moderators
    This might be happening because _debug works in the proxy and and _alert in the browser. Try to use _set when storing browser data

    _set($arry_SubjArea[$i], $allLinksCollected[$i].text);
  • sivasiva Members
    Dear Wormi,

    Tremendous ! its working fine. really great

    Thank you very very very much for your help.


    Regards,
    Sivakumar S
  • globalwormingglobalworming Moderators
    np ;-)
  • sivasiva Members
    Dear Wormi,

    i have small doubt in this line.
    could you please tell me the use of

    "/./"

    in below line. im not getting what is the use of this

    var $allLinksCollected = _collect("_link", "/./", _in(_div("Menutagname1_TreeView1")));

    Thank you


    Regards,
    Sivakumar S
  • globalwormingglobalworming Moderators
    the "/./" is the regular expression, which is matched against the link names. "//" wasn't working, I dont know why..

    _collect("_link", "/./") says: store all links with a name containing anything in an array. google for JavaScript regular expressions and pattern matching, this may be more usefull than me explaining :)
  • sivasiva Members
    Dear Wormi,

    ok now i got it. thanks a lot


    Regards,
    Sivakumar S
Sign In or Register to comment.