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.

use _containsHTML and _containsText

hongmonhongmon Members
edited November -1 in Sahi - Open Source
i write _containsHTML (or _containstext) to Checks for existence of html (or to Checks for existence of text), when me run this script, nothing happen into log. So, how do i know the text existence (i try it with text not right but nothing happen)

Comments

  • narayannarayan Administrators
    _containsHTML or _containsText will just return true or false.
    You will need to assert it.

    Use

    _assert(_containsHTML(el, text));
    _assert(_containsText(el, text));

    or in case of Text you can use

    _assertContainsText(text, el, failureMessage);
  • i run your example at sahi.co.in. The following script:

    _navigateTo("http://sahi.co.in/w/_containshtml";);
    _assertExists(_div("d1"));
    _assertContainsText("Formatted Text", _div("d1"));
    _containsHTML(_byId("d1"), "<i>Formatted</i>") //=true
    _assert(_containsHTML(_byId("d1"), "<i>Formatted</i>"));
    _containsHTML(_byId("d1"), "Text") //=true
    _containsHTML(_byId("d1"), "<i>Formatted</i> Text") //=true
    _containsHTML(_byId("d1"), "Formatted Text") //=false
    _containsHTML(_byId("d1"), "Non existent") //=false

    but playback is failure and view log display line:
    _assert(_containsHTML(_byId("d1"), "Formatted")); Assertion Failed. at Sep 21, 2009 4:21:33 PM
    do you tell my why? thanks
  • narayannarayan Administrators
    Interesting! I ran the same thing and it shows me success! Can you recheck please?
  • pó tay
  • When i use:
    _assert(_containsHTML(_byId("d1"), "<i>Formatted</i> Text"))
    => Assertion failure
    i use your example that run but i can't run.
    please explain for me
    thanks
Sign In or Register to comment.