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 use if and else condition for check box

gunjangunjan Members
edited November -1 in Sahi - Open Source
Hi,
Gunjan here,

I want to capture data from excel sheet and send it on to browser
I am using Sahi v3.5, Windows 7 and Fire fox

Is it possible to check the check box from excel sheet

In my application i have to Check box

My entire zone and Custom zone

Can any body help me how to use if and else for check box

My script is given below

function simplebid($bidnametxt,$zone,$gridrowchecker)
{

_click(_button("Add Bid"));
_setValue(_textbox("bidNameTxt"), $bidnametxt);




_setValue(_checkbox("allZones"),"true");
_click(_checkbox("allZones"));

if(_click(_checkbox("allZones").checked == "false"))
{
_click(_checkbox("custom select"));
}



//_click(_div("x-grid3-row-checker"),$gridrowchecker);
//_click(_div("x-grid3-row-checker[5]"));
//_click(_div("x-grid3-row-checker[2]"));
//_click(_div("x-grid3-row-checker[35]"));
//_click(_image("s.gif[9]"));
//_click(_div("x-grid3-row-checker"),$gridrowchecker);
//_click(_image("s.gif[9]"));

}

// Get the DB instance
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\\Test Data\\Book19.xls;readOnly=false", "", "");

$rs = db.select("select * from [Sheet1$]");

for(var $i=0; $i<$rs.length; $i++)
{

simplebid($rs[$i]["bidNameTxt"],$rs[$i]["all Zones"],$rs[$i]["Customize Zone"],$rs[$i]["x-grid3-row-checker"]);

}

_click(_button("Add Bid"));
_click(_button("Yes"));
_wait(15000,_exists(elememt));

My excel sheet is given below

bidNameTxt all Zones Custome select x-grid3-row-checker
bid1 false true '2


Can u plz help me to solve this problem

waiting for your favorable reply


Thank,
Gunjan.

Comments

  • Hi gunjan,

    Try with the following if condition

    if(_checkbox("allZones").checked == "false")
    {
    _click(_checkbox("custom select"));
    }

    This might help you.

    Regards
    Theeran.
  • Hi,
    Checkbox should not be selected


    Thanks,
    Gunjan.
  • i tried this if and else condition but it should not work



    Thanks,
    Gunjan.
  • Hi gunjan,

    Try the following script,


    if(_condition(!_checkbox("allZones").checked ))
    {
    _click(_checkbox("custom select"));
    }

    This might help you.

    Regards
    Theeran.
  • Hi,


    it should work fine but it show following statement
    Starting script
    _click(_button("Add Bid")); at Nov 11, 2011 5:37:34 PM
    _setValue(_textbox("bidNameTxt"), "Test bid"); at Nov 11, 2011 5:37:36 PM
    _sahi.saveCondition("__lastConditionValue__0", !_checkbox("allZones").checked ) at Nov 11, 2011 5:37:38 PM
    _click(_checkbox("custom select")); at Nov 11, 2011 5:37:40 PM
    _click(_button("Add Bid")); at Nov 11, 2011 5:37:44 PM
    _click(_button("Yes")); at Nov 11, 2011 5:37:45 PM
    _wait(15000, "_exists(elememt)"); at Nov 11, 2011 5:37:57 PM
    Stopping script


    thanks,
    Gunjan.
  • It select Custom zone If I want to select MY entire Zone than?
    in my excelsheet what should my column name and what the condition means true or false?


    Thanks,
    Gunjan.
  • Hi,

    Gunjan here,


    Can anybody help me how to solve this problem?


    Thanks,
    Gunjan.
  • Hi,

    I need to use else if statement for checking the two conditions, i have used the below format but it is not working. Could you please advice anybody?

    if(_assertEqual(_getText(_div("login")),"Invalid username!"))
    {
    _log("<p> <font color='green'>Authentication Checking is working fine, Case1 Pass </font></p>");
    }
    elseif(_assertEqual(_getText(_div("login")),"Invalid password!"))
    {
    _log("<p> <font color='red'>Authentication Checking is working, Case1 pass </font></p>");
    }
    else
    {
    _log("<p> <font color='red'>Authentication Checking is not working, Case1 Fail </font></p>");
    }
  • Hi, looks like a very old post.. but still in case someone needs it,

    you need to write the statement as:

    $text=_getText(_div("login"));
    if($text=="Invalid username!")
    {
    _log("<p> <font color='green'>Authentication Checking is working fine, Case1 Pass </font></p>");
    }
    elseif($text=="Invalid password!")
    {
    _log("<p> <font color='red'>Authentication Checking is working, Case1 pass </font></p>");
    }
    else
    {
    _log("<p> <font color='red'>Authentication Checking is not working, Case1 Fail </font></p>");
    }
Sign In or Register to comment.