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.

text exists?

JuanPereyraJuanPereyra Members
edited May 2011 in Sahi - Open Source
Hi,

the code is:
<div class="block block-user region-count-1 ">
<div class="block-inner clearfix">
<h2 class="title">
<span class="first-word">Text</span>
and more text
</h2>

i try to know if the text : "Text and more text" exists in the html, if exists the script will do some action. (for example an user login)

any ideas to help me with use an if condition, like :

if (_exists(this text) == true)
{
user login
}
else
{ i will write on the log "the user not login" }


Thanks a lot !

from Argentina.

Comments

  • Hello JuanPereya,

    You can use the _containsText(el, txt) API.
    Check if this solves your problem.
    if(_containsText(_heading2("title"), "Text and more text")) {
              //code
    }
    

    Regards,
    dkulkarni
  • Its works !

    the final code:
    var $user = "myUser";
    var $pass = "myPass";
    
    if(_containsText(_heading2("title"), "Can you Login?")) 
    {
        _setValue(_textbox("name"), $user);
        _setValue(_password("pass"), $pass);
        _click(_submit("Login"));
    }
    

    Thanks dkulkarni !
This discussion has been closed.