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.

Exploring SAHI- Data Extraction

NJNJ Members
edited November -1 in Sahi - Open Source
Hi Narayan,

I am a quite new to SAHI. I am basically evaluating it as an option for browser automation. I am trying to extract search result figures (see source code below i.e. 1027 results). I managed to work out using data driven testing to search for results from a CSV files as well as writing it to an out file. But the data extraction bit seem the trickiest.

Is there a way to get SAHI to get text by simply clicking of the location while recording? (I do apologise if the question sounds silly.)

Also, if you are interested, I can help you better market Sahi(based on your wants/expectations). I already have a number of suggestions in mind and that is anyway my area of expertise. Please do mail me if you are interested. I would love to help you out.

Cheers,
NJ

Selection Source
<div class="tabs"> <a href="/search.htm?st1=Global%20Warming&nolog=72091&ct=stp&PHPSESSID=fqj9o4l5haftoquluun4qcu616" title="Search Site Pages.">Site Pages</a> </div>
</div> <p><strong>1027 results found for:</strong> Content = Journals, (<em>Global Warming</em> in All fields)</p>

Comments

  • NJNJ Members
    Can anyone please help me out?

    Thanks
  • narayannarayan Administrators
    Hi NJ,

    Yeah data extraction can be tricky. Here is how you can do it here:
    // There is no id on the element containing your text.
    // use a regular expression to identify the element and then get its text.
    var $resultsText; 
    _set($resultsText, _getText(_strong("/results found for/")));
    // Now $resultsText is "1027 results found for:".
    // We need to get the first number out. We can substring it till the first space
    var $resultsCountStr = $resultsText.substring(0, $resultsText.indexOf(" "));
    _alert($resultsCountStr);
    // $resultsCountStr is now "1027". 
    // If you want to get the integer from string, use parseInt
    var $resultsCount = parseInt($resultsCountStr);
    _alert($resultsCount);
    

    Regards,
    Narayan
Sign In or Register to comment.