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.

(1) DOM functions vs <browser> tag (2) search ignores </browser>

qawebqaweb Members
edited November -1 in Sahi - Open Source
Hi,

Short version
1. The short version of my question may be
do I use <browser></browser> tags around each function that uses DOM object?
or can I put 2 or more functions (and external variables?) in side the tags?
2. I tried to search on this but the search of "<browser>" finds every instance of browser
(side issue: search engine string parsing and keys like PgUp/PgDn, Ctrl-Home are odd:
do not navigate to top of page where search entry form element is. Still your format is very
easy to read with zero eyestrain.)

Long Version
1. I'm testing status messages of new form that creates a new Invoice, PO, Task, etc.
2. I use a function to extract and test messages like "Bug 9876 is now Assigned."
3. I have errors with and without the <browser></browser> tags
3.1. When around only the function(s) (and when I use _call(getvalue($dummy));
ReferenceError: "getValue" is not defined.
3.2. <browser></browser> around the the WHOLE SCRIPT (and the lines that call the functions)
ERROR: in controller (not shown in error / script log)
Object doesn't support this property or method (http://urlundertesthere.com/_s_/dyn/
Player_script/script.js?sahisid=sahi_ebd998820e2cf0415f083e909479e5f08bd9:17)
--Stopped Playback: SUCCESS--
(also echoed to controller DOS console)
Rhino lib:Step >_sahi._click(_sahi._span("Go To"));< did not complete in 150 seconds.
(that would be the next line after failure)
3.3 _currentPOnumber = _call(getValue(_textbox("main_grid2_1_textbox")));
(same as 3.2 "not defined")
also tried it with objDom and objDom.value with and without leading $


These questions arise:
A. what scope, or how to use the browser tags, perhaps searchable examples from Forums ? ^_^
B. Do I need to restart console when an error is logged as in #4 above
C. What in the blue blazes is wrong ... !@$@#$!@#$

<browser>
var $currentPOnumber;

function getValue($objDom)
{ var $someval = $objDom.value;
return $someval;

}

function msgStatusChange($strStatus)
{ // $msgStatusChange = "/PO [0-9].* status changed to /"+$strStatus+".";
return "/PO [0-9].* status changed to /"+$strStatus+"."; }


// _click(_span("/PO 5210 status changed to INPRG\./"));
_wait(_span(function msgStatusChange("INPRG")));

</browser>

var $currentPOnumber;

function getValue($objDom)
{ var $someval = $objDom.value;
return $someval;
}


function getValue2(objDom)
{ // var $someval = $objDom.value;
var $someval;
_setValue($someval, objDom.value);
return $someval;
}

Comments

  • narayannarayan Administrators
    Hi qaweb,

    If you have a custom function for getting a browser attribute, use it in combination with _set.

    Example:
    <browser>
    function getValue($objDom)
    { 
       var $someval = $objDom.value;
       return $someval;
    }
    </browser>
    
    var $currentPOnumber;
    _set($currentPOnumber, getValue(_textbox("main_grid2_1_textbox")));
    
    // Use $currentPOnumber else where in your script.
    

    Custom browser functions will mostly be used for two purposes:

    1) Identifying an element using an identifier which is not supported by Sahi. In this case, the function can be called from any Browser Action API.

    Example:
    <browser>
    function getPlusSignNextToText(txt){
       // use txt to get element
       return element;
    }
    </browser>
    
    _click(getPlusSignNextToText("Folder 1"));
    

    2) Fetching String or numeric values from browser elements, in a way that Sahi's in built APIs do not support. Use it in combination with _set
    <browser>
    function getThirdWordInElement(element){
     return _getText(element).split(" ")[2];
    }
    </browser>
    
    var $thirdWord;
    _set($thirdWord, getThirdWordInElement(_div("messageDiv")));
    _alert($thirdWord);
    


    Hope that helps,
    Regards,
    Narayan
  • beesmanbeesman Members
    edited August 2010
    I also wondered
    <table>
        <tr>
            <td ><div align="left"><strong>FileName</strong></div></td>
            <td >
                kiss.png
            </td>
            <td  rowspan="2" align="right">
                (FileSize7KB)
                <input type="button" value="download" onclick="javascript:download('0','/KissDownloadAction.do');">
            </td>
        </tr>
        <tr>
            <td ><div align="left"><strong>Description</strong></div></td>
            <td >
                sahi test
            </td>
        </tr>
    </table>
    
    

    i want to get kiss.png

    xxx.sah
    function getScreenItem($itemName){
        if(_condition(_cell($itemName) == undefined)){
            return undefined;
        }else{
         _debug(_cell(1, _getText(_near(_cell("FileName"))))); // error (patten 1)
         _debug(_cell(1, _near(_cell("FileName"))).innerHTML);  //error (patten 2)
    
            return _cell(1, _near(_cell($itemName))).innerHTML;
        }
    }
    
    or 
    
    <browser>
    function getScreenItem($itemName){
        if(_condition(_cell($itemName) == undefined)){
            return undefined;
        }else{
           _debug(_cell(1, _near(_cell("FileName"))).innerHTML); // error (patten 3)
           _debug(_cell(1, _getText(_near(_cell("FileName")))));//  error (patten 4)
            return _cell(1, _near(_cell($itemName))).innerHTML;
        }
    }
    
    </browser>
    
    

    both not works

    test.sahi
    _include("xxx.sah");
    _debug(_cell(1, _near(_cell("FileName"))).innerHTML); //kiss.png output
    _debug(_getText(_cell(1, _near(_cell("FileName"))));//  kiss.png output
    _debug(_call(getScreenItem("FileName")));   // error here  (patten 5)
    _debug(getScreenItem("FileName")); <-errr here (patten 6)
    
  • qawebqaweb Members
    problem and fix after re-reading forum / help docs re: using dom objects with loops / writeFile
    (no response needed, but I'm always happy to read your improvements for a better way!)

    this <browser></browser>feature "bites me again!"
    I noticed this works, reporting each real value:
    _log($domObject[$J].className + "," + $domObject[$J].title +_getText($domObject[$J])
    
    but the same dom references do not work in
    _writeFile($sameStringAbove + String.fromCharCode(13) , $reportFile)
    
    until run, one-by-one through a function like this
     _set($tmpClassName,getDomProperty($answers[$k].className));
     _set($tmpTitle,getDomProperty($answers[$k].title));
     
    var $tmp = $z + $spacer + $tmpClassName + $spacer + _getText($answers[$k]) + $spacer + $tmpTitle;
    
    <browser>
    function getDomProperty(someObj){
    return  someObj; }
    </browser>
    

    *** Is there a way to overload (lazy way to skip the individual _set($sahiVar, for each dom var)

    If not, this still works handily, thank you very much for the reminder to not use dom object in a for loop! It saved me quite a bit of time .. I only wasted 1/2 as much before rereading the forums!
Sign In or Register to comment.