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.

searching texts in the current page

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

Does sahi have a function which searches texts in the page?

for example if you only have this simple HTML code:

<html>
<body>
<h3>My Information</h3>
<table>
<tr><td>Name</td><td>numner</td></tr>
<tr><td>my name here</td><td>000000000</td></tr>
</table>
<b>Another Information</b>
</body>
</table>
</html>

I can get the values/texts of the table columns, but I don't know how to get sahi to search for the texts "My Information" and "Another Information".

Is this possible?

Thanks!

Comments

  • narayannarayan Administrators
    Use:
    _assertTrue(_containsText(document.body, "My Information"));
  • tinchie8tinchie8 Members
    Thanks naranayan!
  • Hi, I have a similar problem. I am using the Sahi APIs for executing my tests from a FitNesse fixture (see fitnesse.org). I am basically writing methods that are similar to the JAVA examples that come with Sahi. Some examples of the types of assertions I am doing look like this:

    public boolean assertDivTextEquals(String identifier, String text){
    return browser.div(identifier).getText().equals(text);
    }

    public boolean assertCellExists(String identifier){
    return browser.cell(identifier).exists();
    }

    public boolean assertCellIsVisible(String identifier){
    return browser.cell(identifier).isVisible();
    }
    ...and so on.

    Ideally, it would be something like this, with "text" being set to 'Error' or 'Exception':
    public boolean assertTextNotVisible(String text){
    return !document.body.containsText(text);
    }


    Unfortunately, I am not able to find a browser object that represents the 'document.body' that is available in the Sahi script, like you mentioned previously. I don't know if it makes a difference, but my class is not extending the junit TestCase as the example java project does. Instead it is extending a FitNesse Sequence fixture, which is used to execute the test.(necessary for running from within FitNesse).

    Any ideas?
  • It looks like I posted too soon. I found an example DriverClientTest.java that has a similar identifier:

    browser.accessor("document.body").containsHTML()

    I think I can go ahead and use this:

    public boolean assertTextNotVisible(String text){
    return !browser.accessor("document.body").containsText(text);
    }

    I will give it a shot!
Sign In or Register to comment.