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.

Variable assignments/storing

kphapakdykphapakdy Members
edited November -1 in Sahi - Open Source
Hi. I had looked through Sahi forum and tried a few suggestions but can not get my script to work. When I run the script below I get an error: _sahi.setServerVar('\$objId', getObjValById("SelectSorting_Chart_1", "src"));
TypeError: Object expected

I have created a function to obtain specified object property by inputting the object id

function getObjValById($id, $prop){

eval("var $val = document.getElementById($id)." + $prop);
return $val;
}

// Here I am assigning the value returned from the function to the var $objId
var $objId;
_set($objId,getObjValById("SelectSorting_Chart_1", "src"));

// if var $objID equals to the value indicated then click on the image, else alert "OOPS!"
if ($objId == "*H_Charting/sortA.gif"){
_click(_image("SelectSorting_Chart_1"));

}
else{
_alert ("OOPS!")
}

Comments

  • narayannarayan Administrators
    getObjValById should be a browser function.

    Use:
    
    <browser>
    function getObjValById($id, $prop){
      return document.getElementById($id)[$prop];
    }
    </browser>
    
    var $objId;
    _set($objId, getObjValById("SelectSorting_Chart_1", "src"));
    
    // if var $objID equals to the value indicated then click on the image, else alert "OOPS!"
    if ($objId == "*H_Charting/sortA.gif"){
      _click(_image("SelectSorting_Chart_1"));
    }
    else{
      _alert ("OOPS!")
    }
    
    
  • This works. Thank you so much.
This discussion has been closed.