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.

How to handle dynamic links with sahi

rajathummalarajathummala Members
edited November -1 in Sahi - Open Source
Hi,

I am facing one issue that is when we search for one keyword, then it will list out the number of keyword links in search result.When i spy on links, there is no unique property to identify the link on webpage.
For eg:
link1----SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_1_Title
link2----SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_2_Title
link3----SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_3_Title

How can we handle by using reguler expression.

Please provide the solution to resolve..


Thanking you in advance..


Regards
Raja

Comments

  • Hi Raja,

    Try using

    SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_/.*/_Title

    Check if this solves your issue.

    Regards
    Sumitra
  • rajathummalarajathummala Members
    edited February 2012
    Hi Sumitra,

    Thanks for reply, Please have a look at the below code.

    var $content = _readFile("C:/Users/xxxx/sahi_pro/userdata/scripts/Inputdata.txt");
    //_alert($content);
    var $lines = new Array();
    $lines =$content.split("\n");
    for (var $i = 0; $i < $lines.length; $i++){
    var $uid = new Array();
    $uid = $lines[$i];
    //_alert($uid);
    _navigateTo("http://www.google.com";);
    _setValue(_textbox("ctl00\$PlaceHolderSearchArea\$ctl01\$S3031AEBB_InputKeywords"), $uid);
    _click(_image("Search"));
    var $x=_count("_link","/SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_\.*\_Title/");
    _alert($x);
    for (var $i=1; $i<=$x; $i++) {
    var $y = _getText(_link("/SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_$i_Title/"));
    _alert($y);
    //_writeCSVFile($y($i) +"\n","C:/Users/xxx/sahi_pro/userdata/scripts/Inputdata.csv");
    }
    }

    Please reply me..
    I tried as you suggested, but its not working

    Regards
    Raja
  • Hi rajathummala,

    Use:
    var $x=_count("_link","/^SRB_g_/");
            _alert($x);
    

    Also, change this:
    var $y = _getText(_link("SRB_g_17c830c2_a4f1_4e4d_a332_c2fa1e46da59_" + $i + "_Title"));
            _alert($y);
    

    Regards,
    dkulkarni
  • Hi Kulkarni,

    Thank you so much.. its working now..


    Thanks a lot for your wonderful support.............:)

    Regards
    Rja
This discussion has been closed.