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 retrieve data from drop down

gunjangunjan Members
edited November -1 in Sahi - Open Source
Hi,
I am Gunjan.
Can you please tell me how to retrieve data from drop down?

I want to capture data from excel sheet and export in FIRE FOX
i am using windows7,Fire fox,Sahi V 3.5

My excel sheet is

FirstName LastName idCellPhone1 idCellPhone2 idMail YearID MakeID
Gunjan Radadia 111 7868767 abs@abc.com 1990 Audi

ModelID idcolors
A4 Senden blue



in this above sheet,
YearID, MakeID, ModelID, idcolor are Drop down values

can u plz help me?


Thanks,
Gunjan.

Comments

  • TheeranTheeran Members
    edited October 2011
    Hi gunjan,

    To capture the data from the excel sheet and send it to the browser,use the following script,
     var $db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", 
                           "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};
                       DBQ="+ filePath +";readOnly=false", 
                           "", 
                           "");
    $rs = $db.select("select * from [Sheet1$]");
    _setValue(_textbox("textboxid"),$rs[0]["columnIndex"]);
    
    

    This might help you.
    let us know if the problem persists.

    Regards
    Theeran.
  • Hi
    I am not getting proper output

    My script is given below


    function contactInfo($fname,$lname,$daytimephone1,$daytimephone2,$email,$year,$make,$model,$color)
    {

    _setValue(_textbox("FirstName"), $fname);
    _setValue(_textbox("LastName"), $lname);
    _setValue(_textbox("idCellPhone1"), $daytimephone1);
    _setValue(_textbox("idCellPhone2"), $daytimephone2);
    _setValue(_textbox("idMail"), $email);
    _setSelected(_select("YearID"), $year);
    _setSelected(_select("MakeID"), $make);
    _setSelected(_select("ModelID"), $model);
    _setSelected(_select("idcolors"), $color);



    }

    // 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\\Book3.xls;readOnly=false", "", "");

    $rs = db.select("select * from [Sheet1$]");
    _setValue(_textbox("textboxid"),$rs[4]["columnIndex"]);
    contactInfo($rs[4]["FirstName"], $rs[4]["LastName"], $rs[4]["idCellPhone1"], $rs[4]["idCellPhone2"], $rs[4]["idMail"],
    $rs[4]["YearID"], $rs[4]["MakeID"],$rs[4]["ModelID"],$rs[4]["idcolors"]);



    and my excel sheet is also given below

    FirstName LastName idCellPhone1 idCellPhone2 idMail YearID MakeID
    trupti ranparia 565 1238596 tgr@tgr.com 2008 Audi

    ModelID idcolors
    A4 Sendan Blue

    My excel sheet name is Book3.xls


    Error:

    Starting script
    _setValue(_textbox("textboxid"),null); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("FirstName"), "trupti"); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("LastName"), "ranparia"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone1"), "565.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone2"), "1238596.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idMail"), "tgr@tgr.com"); at Oct 31, 2011 10:19:38 AM
    _setSelected(_select("YearID"), "2008.0");
    Error: Option not found: 2008.0
    http://192.168.1.4/_s_/spr/concat.js:1203
    http://192.168.1.4/_s_/spr/concat.js:1235
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:2822

    Click for browser script
    at contactInfo (scripts/JMCCIVI1.sah:10) at Oct 31, 2011 10:19:48 AM
    Stopping scrip
  • Hi Gunjan,

    It seems like your format in Excel sheet is different. Make it to integer. Script is failing cause drop down list contains value "2008".... not "2008.0".

    Script will work fine if you change it to integer number in your excel sheet.
  • gaveyomgaveyom Members
    edited October 2011
    Hi Gunjan,

    in ur script i have observed that " columnIndex " column is not mentioned in ur excel file but u r trying to access which is not present in excel sheet


    u mentioned that below columns are present in excel sheet

    FirstName LastName idCellPhone1 idCellPhone2 idMail YearID MakeID
    trupti ranparia 565 1238596 tgr@tgr.com 2008 Audi
    ModelID idcolors
    A4 Sendan Blue

    but u r trying to access the column which was not exist in ur excel sheet

    include the " columnIndex " column in ur excel sheet and run the script, hence it will execute correctly

    other wise send me ur excel sheet i will check it once and give the solution
    u can send ur excel sheet to alliswellplssmile@gmail.com
  • Error:
    Starting script
    _setValue(_textbox("textboxid"),null); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("FirstName"), "trupti"); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("LastName"), "ranparia"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone1"), "565.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone2"), "1238596.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idMail"), "tgr@tgr.com"); at Oct 31, 2011 10:19:38 AM
    _setSelected(_select("YearID"), "2008.0");
    Error: Option not found: 2008.0
    http://192.168.1.4/_s_/spr/concat.js:1203
    http://192.168.1.4/_s_/spr/concat.js:1235
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:2822

    Hi gaveyom,

    Please take a look at error that gunjan has posted.

    Its not giving error for that ColumnIndex. Its just normal text box and if no value found from excel then it will assign "NULL" to it.

    Error is thrown at the time of setting value of year from drop down. Which seems to be "2008" in drop down list and value fatched from the excel sheet is "2008.0".
  • Hi gunjan,

    Try the following script,
    function contactInfo($fname,$lname,$daytimephone1,$daytimephone2,$email,$year,$make,$model,$color)
    {
    
    _setValue(_textbox("FirstName"), $fname);
    _setValue(_textbox("LastName"), $lname);
    _setValue(_textbox("idCellPhone1"), $daytimephone1);
    _setValue(_textbox("idCellPhone2"), $daytimephone2);
    _setValue(_textbox("idMail"), $email);
    _setSelected(_select("YearID"), $year);
    _setSelected(_select("MakeID"), $make);
    _setSelected(_select("ModelID"), $model);
    _setSelected(_select("idcolors"), $color);
    }
    
    // Get the DB instance
    var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\\Documents and Settings\\Sumitra\\Desktop\\Book3.xlsx;readOnly=false", "", "");
    $rs = db.select("select * from [Sheet1$]");
    contactInfo($rs[1]["FirstName"], $rs[1]["LastName"], $rs[1]["idCellPhone1"], $rs[1]["idCellPhone2"], $rs[1]["idMail"], 
    ""+parseInt($rs[1]["YearID"]), $rs[1]["MakeID"],$rs[1]["ModelID"],$rs[1]["idcolors"]);
    

    This might help you.

    let us know if the problem persists.

    Regards
    Theeran.
  • gaveyomgaveyom Members
    edited October 2011
    Akss004 wrote:
    Error:
    Starting script
    _setValue(_textbox("textboxid"),null); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("FirstName"), "trupti"); at Oct 31, 2011 10:19:37 AM
    _setValue(_textbox("LastName"), "ranparia"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone1"), "565.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idCellPhone2"), "1238596.0"); at Oct 31, 2011 10:19:38 AM
    _setValue(_textbox("idMail"), "tgr@tgr.com"); at Oct 31, 2011 10:19:38 AM
    _setSelected(_select("YearID"), "2008.0");
    Error: Option not found: 2008.0
    http://192.168.1.4/_s_/spr/concat.js:1203
    http://192.168.1.4/_s_/spr/concat.js:1235
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:3016
    http://192.168.1.4/_s_/spr/concat.js:2822

    Hi gaveyom,

    Please take a look at error that gunjan has posted.

    Its not giving error for that ColumnIndex. Its just normal text box and if no value found from excel then it will assign "NULL" to it.

    Error is thrown at the time of setting value of year from drop down. Which seems to be "2008" in drop down list and value fatched from the excel sheet is "2008.0".





    Hi Akss004,

    we will get this " null " issue due to not existing of " columnIndex " column only

    when we try to get the value of not existing column from excel sheet it will return " null " value

    if we remove the below line from script it will run correctly

    _setValue(_textbox("textboxid"),$rs[4]["columnIndex"]);

    or

    other way to execute the script, we can include this column in excel sheet, so that it can run correctly

    either one way we can use
  • Hi,
    Can u plz tell me how to use FOR loop for my example
    and capture data from excel sheet and export it in to browser.



    Thanks,
    Gunjan.
  • Hi Gunjan,

    below is the code with for loop


    ******************************************************************************



    function contactInfo($fname,$lname,$daytimephone1,$daytimephone2,$email,$year,$make,$model,$color)
    {

    _setValue(_textbox("FirstName"), $fname);
    _setValue(_textbox("LastName"), $lname);
    _setValue(_textbox("idCellPhone1"), $daytimephone1);
    _setValue(_textbox("idCellPhone2"), $daytimephone2);
    _setValue(_textbox("idMail"), $email);
    _setSelected(_select("YearID"), $year);
    _setSelected(_select("MakeID"), $make);
    _setSelected(_select("ModelID"), $model);
    _setSelected(_select("idcolors"), $color);
    }



    // Get the DB instance
    var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\\Documents and Settings\\Sumitra\\Desktop\\Book3.xlsx;readOnly=false", "", "");
    $rs = db.select("select * from [Sheet1$]");
    for(var $i=0; $i<$rs.length; $i++) {

    contactInfo($rs[$i]["FirstName"], $rs[$i]["LastName"], $rs[$i]["idCellPhone1"], $rs[$i]["idCellPhone2"], $rs[$i]["idMail"],
    ""+parseInt($rs[$i]["YearID"]), $rs[$i]["MakeID"],$rs[$i]["ModelID"],$rs[$i]["idcolors"]);
    }



    ******************************************************************************
  • Hi

    i m gunjan
    When i submit the claim it takes little time,
    And if i want to submit multiple claims i can't do because of claim submission takes time.
    I want to capture data from excel sheet and send it on the Browser.

    Can u please help how to solve this problem?
    I am using windows 7, Sahi V3.5, and Browser fire fox 5.0

    Thanks,
    Gunjan.
  • Hi gunjan,

    Have you tried the above script?

    when you submit the claim it may take some time to process it and once it is processed it will return an element with either success or failure.so you have to trigger the next test based upon the completion of the first test.so use _wait() API to wait for some time and trigger the next test upon the existence of the result element.

    syntax:

    _wait(time,condition);

    time--The time to wait.
    condition--The condition to be satisfied for triggering the next test.
    Foreg:

    _wait(10000,_exists(element));

    Append it as the last line inside the for loop.

    Then the second test will be triggered only if the first test is completed and the result element is displayed.

    Regards
    Theeran.
  • thank u very much it's works fine
This discussion has been closed.