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.

Error message when we try to run Excel Object API

edited November -1 in Sahi - Open Source
I'm using Sahi for the first time, we are trying to automate web application.

I'm using the below code in order to get the data from the excel..the excel sheet is having two columns in the sheet1..the columns name being userName and password...Under userName and password .....i've given the corresponding values...

I'm getting the following error when I try to run the below mentioned code:

Error Message:- JSERROR SyntaxError: syntax error(This error is shown in the log file)

I'm using MS office 2007.

Please see the below mentioned code given below that I've used as part of the script...

var $db = _getDB("sun.jdbc.odbc.jdbcOdbcDriver","jdbc:odbc:Driver={Microsoft Excel Driver(*.xls);DBQ=C:\Documents and Settings\208494\Desktop\Param\parameterization.xls","","");
var $XlsData =[];
$XlsData[0]=[];
var $XlsData = $db.select("select * from [Sheet1$]]");
var $data1 =($XlsData[0]["userName"]);
var $data1 =($XlsData[0]["password"]);

_setValue(_textbox("tbUserName"),($XlsData[0]["userName"]));
_setValue(_password("tbPassword"), "),($XlsData[0]["password"]));
_click(_imageSubmitButton("imgLogin"));


Is there any settings that I need to do before using the above mentioned..

Please help..

Regards,
Pavan.
Tagged:

Comments

  • dpdp Members
    Hi Pavan,

    Please read this post to know more about accessing Excel from Sahi: http://sahi.co.in/w/working-with-excel-sheets

    I find two issues in your code:

    1. The path to the Excel sheet should either use forward slash ( / ) or double slashes ( \\ )
    2. Remove the extra closing square bracket at the end of the select statement. It should look like $db.select("select * from [Sheet1$]");

    Hope this helps.

    BTW, your code looks familiar. By any chance did you post it earlier?

    Cheers
    Dilip
  • narayannarayan Administrators
    Hi Pavan,

    There are a few errors in the _getDB statement above which is causing Sahi to throw exceptions, but the error message is not correctly pointing to the exception. If you look at the command prompt where you ran sahi.bat from, you will see a classnotfound exception. That is because the jdbcOdbcDriver should be JdbcOdbcDriver (capital J) There are more errors, like a missing space and bracket and backslashes are not escaped. I would suggest you copy the code from http://sahi.co.in/w/working-with-excel-sheets and change only the filepath with backslashes escaped.

    (Well, since I have already debugged it, here is what you can use)
    var $db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};C:\\Documents and Settings\\208494\\Desktop\\Param\\parameterization.xls;readOnly=false", "", "");
    

    Regards,
    Narayan
Sign In or Register to comment.