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 check checkbox from my excel sheet?

gunjangunjan Members
edited November -1 in Sahi - Open Source
Hi
Gunjan here,
I am using windows 7, sahi v3.5 and firefox 5.0
Can u plz tell me how to select checkbox from excel sheet?


i want to capture data from excel sheet and send it on browser

now, my problem is
i have one form in this form i have 2 checkbox one is "My Entire Zone" second is "Customize zone"

When i checked My Entire Zone check box it select all the Zones saved on database
But when i checked on " Customize zone" it display zone menu and i can select custom zone

My Script is given below

function simplebid($bidnametxt,$zone,$zone1,$gridrowchecker,$year,$setyeararrange,$selectmakes,$available,$allownershiptype,$allownershiptype,$allvehiclescondition)
{

_click(_button("Add Bid"));
_setValue(_textbox("bidNameTxt"), $bidnametxt);
_click(_checkbox("allZones"),$zone1);
if($zone1=="Null")
{
_click(_checkbox("Customize Zone"),$zone);
_click(_span("Customize Zone"),$zone);
}
else
{


}
//_click(_checkbox("Customize Zone"),$zone);

//_click(_span("Customize Zone"),$zone);
_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]"));

_click(_div("Year"),$year);
_click(_image("s.gif[10]"));
_click(_div("SetYearArrange"),$setyearrange);
_click(_image("s.gif[11]"));
_click(_div("Selected Makes"),$selectmakes);
_click(_div("x-column-inner[5]"));
//_click(_emphasis("AMC"));
_click(_div("Available"),$available);
//_click(_image("right2.gif"));
//_click(_emphasis("Acura"));
//_click(_image("right2.gif"));
_click(_checkbox("All Ownership Types"),$allownershiptype);
_click(_checkbox("All Ownership Types"),$allownershiptype);
_click(_checkbox("allVehicleConditions"),$allvehiclescondition);
_click(_checkbox("allVehicleConditions"),$allVehicleConditions);
_setValue(_textbox("bidAmountTxt"),$bidamount);
_click(_button("Add Bid"));
//_click(_cell("x-btn-bc[6]"));
//_click(_button("Yes"));
//_wait(15000,_exists(elememt));
}


// 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\\Book17.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"],""+parseInt($rs[$i]["x-grid3-row-checker"]),""+parseInt($rs[$i]["x-grid3-row-checker"]),""+parseInt($rs[$i]["All Years"]),$rs[$i]["SetYearArrange"],$rs[$i]["Selected Makes"],$rs[$i]["Available"], $rs[$i]["All Ownership Types"],$rs[$i]["All Ownership Types"],$rs[$i]["allVehicleConditions"],$rs[$i]["allVehicleConditions"],""+parseInt($rs[$i]["bidAmountTxt"]));

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


}


my excel sheet is also given below
bidNameTxt Customize Zone x-grid3-row-checker x-grid3-row-checker
Bid1 Customize zone 2 3


All Years SetYearArrange All Makes All Ownership Types
2004 New Selected Makes Documented


allVehicleConditions bidAmountTxt
vehicles with engine and transmission 1200



it is also possible that my excel sheet is wrong

when i select year i have to select SetYearArrange, SetYearArrange is dropdown list and it contain 2 values "New" and "Old".When i select year 2004 and also select "New" it consider year 2004,2005,2006,2007,2008,2009,2010,2011,2012.


Similarly, "Set Makes" is title on my form, In my excel sheet the column is "All Makes". "Set Makes" also a drop down list it contain two values "All Makes" And "Selected Makes" when i select "All makes" it select all car model save in my Database when i select "Selected make" i can select particular cars model

It display Available cars list and i can select the car and click on "Arrow" the car model is move in "Selected" Text area


Can u plz help me to solve this problem?

Error is given below:


Starting script
_click(_button("Add Bid")); at Nov 10, 2011 11:03:25 AM
_setValue(_textbox("bidNameTxt"), "Bid custome zone"); at Nov 10, 2011 11:03:27 AM
_click(_checkbox("allZones"),"Customize Zone"); at Nov 10, 2011 11:03:27 AM
_click(_div("x-grid3-row-checker"),"2"); at Nov 10, 2011 11:03:27 AM
_click(_image("s.gif[9]")); at Nov 10, 2011 11:03:27 AM
_click(_div("x-grid3-row-checker"),"2"); at Nov 10, 2011 11:03:28 AM
_click(_image("s.gif[9]")); at Nov 10, 2011 11:03:29 AM
_click(_div("Year"),"2");
Error: The parameter passed to _click was not found on the browser
at simplebid (scripts/bid4.sah:28) at Nov 10, 2011 11:03:42 AM
Stopping script



Waiting for your favorable reply.

Thanks,
Gunjan.

Comments

  • Hi Gunjan,

    Can you check if _div("year") is present on your application?

    Also, can you Ctrl+Hover on the div and check if its been identified as _div("year") or some thing else.

    Let me know if _div("year") is a dropdown?

    Also, try using _wait() API.

    Regards
    Sumitra
  • Hi sumitra,
    Yes it is drop down
  • Hi

    It is my drop down list

    Can u plz help me i want tosolve this as soon as possible

    Thanks,
    Gunjan
  • Hi Gunjan,

    Kindly check the usage of the _click() API.

    Also, the steps which are dependent to perform _click(_div("year","2"));

    _click(_checkbox("allZones"),"Customize Zone"); This usage seems to be incorrect.

    _click simulates a user’s click on the given element.The parameter passed to click an checkbox is only one, according to your application its allZones.

    Here is the details about _click() API:
    http://sahi.co.in/w/_click

    Regards
    Sumitra
  • _click(_checkbox("allZones"),"Customize Zone"); This usage seems to be incorrect.
    _click simulates a user’s click on the given element.The parameter passed to click an checkbox is only one, according to your application its allZones.


    I can't understand plz can u explain in detail?



    Thanks,
    Gunjan.
  • function simplebid($bidnametxt,$zone,$zone1,$gridrowchecker,$year,$setyeararrange,$selectmakes,$available,$allownershiptype,$allownershiptype,$allvehiclescondition)
    {

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

    //_click(_checkbox("id")) will check/unckeck the checkbox.
    //_assert(_checkbox("id").checked) will assert if _checkbox is checked.

    _click(_checkbox("allZones"),$zone);
    _assert(_checkbox("allZones").checked)

    if (_condition(_checkbox("allZones").checked == false))
    {

    _click(_checkbox("custom select"));
    _click(_span("Customize Zone"));

    _click(_span("Customize Zone"),$zone);
    }


    //_click(_checkbox("Customize Zone"),$zone);

    //_click(_span("Customize Zone"),$zone);
    _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]"));

    _click(_div("SetYearRange"),$year);
    _click(_image("s.gif[10]"));
    _click(_div("SetYearArrange"),,$setyeararrange);
    _click(_image("s.gif[11]"));
    _click(_div("Selected Makes"),$selectmakes);
    _click(_div("x-column-inner[5]"));
    //_click(_emphasis("AMC"));
    _click(_div("Available"),$available);
    //_click(_image("right2.gif"));
    //_click(_emphasis("Acura"));
    //_click(_image("right2.gif"));
    _click(_checkbox("All Ownership Types"),$allownershiptype);
    _click(_checkbox("All Ownership Types"),$allownershiptype);
    _click(_checkbox("allVehicleConditions"),$allvehiclescondition);
    _click(_checkbox("allVehicleConditions"),$allVehicleConditions);
    _setValue(_textbox("bidAmountTxt"),$bidamount);
    _click(_button("Add Bid"));
    //_click(_cell("x-btn-bc[6]"));
    //_click(_button("Yes"));
    //_wait(15000,_exists(elememt));
    }


    // 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\\Book17.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"],""+parseInt($rs[$i]["x-grid3-row-checker"]),""+parseInt($rs[$i]["SetYearRange"]),$rs[$i]["SetYearArrange"],$rs[$i]["Selected Makes"],$rs[$i]["Available"], $rs[$i]["All Ownership Types"],$rs[$i]["All Ownership Types"],$rs[$i]["allVehicleConditions"],$rs[$i]["allVehicleConditions"],""+parseInt($rs[$i]["bidAmountTxt"]));

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


    }

    My Script is expain
  • if is not working perfect
  • because it is not select customize zone
  • i think if statement is not working properly
    and when i record the script my first script record explain below



    _setValue(_textbox("bidNameTxt"), "year bid");
    _click(_checkbox("custom select"));
    _click(_span("Customize Zone"));
    _click(_div("x-grid3-row-checker[1]"));
    _click(_div("x-grid3-row-checker[6]"));
    _click(_div("x-grid3-row-checker[8]"));
    _click(_image("s.gif[9]"));
    _click(_div("2007"));
    _click(_image("s.gif[10]"));
    _click(_div("Newer"));
    _click(_image("s.gif[11]"));
    _click(_div("Selected Makes"));
    _click(_emphasis("Acura"));
    _click(_image("right2.gif"));
    _click(_emphasis("Aston Martin"));
    _click(_image("right2.gif"));
    _click(_checkbox("1"));
    _click(_checkbox("excludeMissingEngineOrTransmission"));
    _setValue(_textbox("bidAmountTxt"), "10");
    _click(_button("Add Bid"));
    _click(_button("Yes"));



    Can u plz see this script and help me?

    Thanks,
    Gunjan.
  • _click(_div("All Years"),$year); is it true?
  • _click(_div("x-grid3-row-checker[1]"));
    could not select checkbox

    _click(_div("2007"));

    could not select year from drop down
  • Hi, When i ctrl+hover
    Year syntxt is

    _textbox("cmb Year")
    _textbox("cmb Year")
    2004

    when i playback script it display
    _click(_div("2004"));
  • Hi Gunjan,

    It seems like your script has errors.
    1. If the application is identifying the "Year" field as textbox("cmb Year") but playback has
    _click(_div("2004")); then please check this
    Is there an image next to the textbox? If yes, on clicking the image, is a drop down generated?
    If yes, I think you need to add _click on image and then _click on _div("2004").

    2. _click API takes two parameters only. Syntax: _click(el, COMBO);
    You CANNOT use _click(_div("All Years"),$year); This usage is INCORRECT. I think it should be _click(_div("All Years")); Please verify.

    3. Make sure you parameterize your function correctly, i.e., make sure you pass the right values to your steps.

    4. if($zone1=="Null")
    This usage looks incorrect. If you want to verify if a value is null, then please use
    if($zone1==null)
    

    Try to execute your steps a few at a time. You can then point to the exact place of fault.

    Regards,
    Sumitra
  • Hi Sumitra,


    Shall we solve our first problem?

    How to check or uncheck checkboxes from my excel sheet?

    How to use if end else statement for checkboxes?


    my script is given below

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

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









    _wait(15000,_exists(elememt));

    _click(_checkbox("allZones"),$zone1);

    if($zone1==null)
    {
    _click(_checkbox("Custome select"),$zone);
    _click(_span("Customize Zone"),$zone);
    }
    else
    {
    _click(_checkbox("allZones"),$zone1);

    }






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

    //_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]["Custome select"],$rs[$i]["x-grid3-row-checker"]);

    }

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


    it select only My Entire Zone

    and my excel sheet is given below


    bidNameTxt all Zones Custome select x-grid3-row-checker
    Test Bid null Customize Zone '4



    Can u plz help me how to solve it?

    Waiting for your favorable reply.


    Thanks,
    Gunjan.
  • Hi

    Gunjan here,


    Can anybody help me to solve this problem?


    Waiting for your favorable reply


    Thanks,
    Gunjan.
Sign In or Register to comment.