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.

Help with _getCellText

rlohmanrlohman Members
edited November -1 in Sahi - Open Source
Hi, all:
I'm having trouble grabbing the content of a cell. I'm trying to accomplish the following:

1. Display a page with a table of data.
2. Copy the content of one cell in that table, and store it in a variable.
3. Perform some action (which results in changing the content of the cell previously copied).
4. Copy the new content of the same cell in the table.
5. Compare the two variables with an _assertNotNull to verify that they are not the same.

The cell is accessed as _cell(_table(2), 1, 3)
The code I'm using is:

01: var $firstAmt = 0;
02: var $secondAmt = 0;
03:
04: //MARK: Print the first item in the list.
05: _click(_link("Bulk Printing"));
06: _setValue(_textbox("entity-inputentityChoice"), "t");
07: _setSelected(_select("entityChoice"), "Test Company");
08: _click(_imageSubmitButton(0));
09: _wait(2000);
10: $firstAmt = _getText(_cell(_table(2), 1, 3));
11: _setValue(_checkbox("prn"), "true");
12: _click(_imageSubmitButton(0));
13:
14: //MARK: Give the user time to download and print the check
15: _wait(10000);
16:
17: //MARK: Verify the item no longer appears in the list.
18: _click(_link("Bulk Printing"));
19: _setValue(_textbox("entity-inputentityChoice"), "t");
20: _setSelected(_select("entityChoice"), "Test Company");
21: _click(_imageSubmitButton(0));
22: $secondAmt = _getCellText(_cell(_table(1), 0, 1));
23: _assertNotEqual($secondAmt, $firstAmt, "Check not removed from Bulk Print List");

It seems to keep breaking on line 10 (line 09 appears to complete successfully). Ideally, after I perform work on the data (lines 11 and 12), the value stored in _cell(_table(2), 1, 3) should change.

Any ideas?
Thanks.

RJL

Comments

  • narayannarayan Administrators
    edited December 2007
    var $firstAmt = 0;
    var $secondAmt = 0;
    
    //MARK Print the first item in the list.
    
    _click(_link("Bulk Printing"));
    _setValue(_textbox("entity-inputentityChoice"), "t");
    _setSelected(_select("entityChoice"), "Test Company");
    _click(_imageSubmitButton(0));
    _wait(2000);
    
    
    _set($firstAmt, _getText(_cell(_table(2), 1, 3)));
    _setValue(_checkbox("prn"), "true");
    _click(_imageSubmitButton(0));
    
    //MARK Give the user time to download and print the check
    _wait(10000);
    
    //MARK Verify the item no longer appears in the list.
    _click(_link("Bulk Printing"));
    _setValue(_textbox("entity-inputentityChoice"), "t");
    _setSelected(_select("entityChoice"), "Test Company");
    _click(_imageSubmitButton(0));
    
    _set($secondAmt, _getCellText(_cell(_table(1), 0, 1)));
    _assertEqual($secondAmt, $firstAmt, "Check not removed from Bulk Print List");
    
    A few changes have been made:

    _set is used instead of direct assignment
    _assertEqual is used for comparison.
  • Why can't sahi does not allows assinging cell text directly to variable?
  • narayannarayan Administrators
    Sumeet,

    Sahi's script executes on the proxy. cellText has to be fetched from the browser. So you have to tell it to execute the _getCellText on the browser, get it to the proxy and store it in your variable. Another approach could have been to always serialize and send back the content to the proxy, but it adds a lot of overhead to the browser's communication with the proxy. It also prevents Sahi from being able to retry a failed line multiple times.

    Do you find this to be annoying or inconvenient? We can try and think up something else.

    Regards,
    Narayan
Sign In or Register to comment.