18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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 identify newly added row in a page that displays records.
Q1) I am working on this web app that allows you to make certain financial transactions. In some transactions, the transaction detail input page contains a unique field that will appear among the attributes of the row of a newly made transaction in the transactions listing. So I could just store the value of that field in a global variable and use that to identify the new row in the transactions listing.
In other cases, no unique fields that appear in the transaction listing are contained in the "make new transaction page." A newly made transaction is given a unique ID that only appears in the transactions listing after you make the transaction. How would one identify a new row then?
What I currently have in mind is that since before you go to the "make new transaction page" you have to first be at the transaction listing page, one could store the IDs of the existing transactions in an array. After a new transaction is made and one goes back to the transaction listing, one could then compare the ID of every listed transaction with each element in the array. The new row is detected when an ID that's not in the array is encountered. The problem with this is that it would probably take rather long if there are many existing transactions.
Q2) What command can I use in the script to access the alternative accessors of an element? E.g. Access the alternative accessor "_cell(49)" of element _cell("XYZ")
Thank you!
In other cases, no unique fields that appear in the transaction listing are contained in the "make new transaction page." A newly made transaction is given a unique ID that only appears in the transactions listing after you make the transaction. How would one identify a new row then?
What I currently have in mind is that since before you go to the "make new transaction page" you have to first be at the transaction listing page, one could store the IDs of the existing transactions in an array. After a new transaction is made and one goes back to the transaction listing, one could then compare the ID of every listed transaction with each element in the array. The new row is detected when an ID that's not in the array is encountered. The problem with this is that it would probably take rather long if there are many existing transactions.
Q2) What command can I use in the script to access the alternative accessors of an element? E.g. Access the alternative accessor "_cell(49)" of element _cell("XYZ")
Thank you!
Best Answer
-
Hi
Q1) I would do it the same way, store ids in an array then _collect all the transactions. Compare the transactions to the array for equal ids.. if no is found, you have a new transaction. You may speed things up by knowing if new transactions will appear at the top or bottom. I when its sort by date and newest first its pretty fast
Q2) Access the alternate accessor of $element... why would you want to do this? Do you need the index (49 in your case)?
I guess there is no method to return alternate accessors... but have a look at http://sourceforge.net/p/sahi/code/HEAD/tree/trunk/sahi/htdocs/spr/concat3.js how these accessors are generated, you should be able to do the same with javascript.
Regards
Wormi

Answers
Q1) If it's sorted according to transaction ID so that a new transaction is always placed at the end, is the following the way to go about doing it? Get the cell number of the trans. ID of the first row, store it in $cellIndexNewTrans, and then loop the following three actions: add the offset (no. of other attributes of each trans. in the row) to $cellIndexNewTrans, check the text content of the cell with that number to see if it is a trans. ID, and exit loop if it's not. Then the no. of the cell of the trans. ID of the new transaction would be '$cellIndexNewTrans - no. of other attributes'.
Q2) var $els = _collect (”_link”, “/group 1/”, _in(_div(“div1”))); (gotten from Sahi API)
May I know what "/group 1/" means? How would I use this method to collect all the transaction ID cells of the transaction records in a table?
Q3) Why I need the alternate accessor:
When I create a new currency, I want to check that a new record (row) is created in the currency listing. Since in this case the currency short and long names are unique and are input in the "make new currency page", I could store them in global variables and use them to identify the new row in the currency listing. However, the accrual method attribute, which is in the adjacent right cell of the "currencyLong" cell, is not unique. So I tried to use the below third assertion to check if the right accrual method is reflected. But it does not work (Btw, each attribute value is enclosed in a span tag which is in turn enclosed in a cell tag). So now I want to use the cell ID of "_cell($currencyLong)" and add 1 to it to get the id of the accrualMethod cell.
_assertExists(_cell($currency));
_assertExists(_cell($currencyLong));
_assertContainsText($accrMeth, _getText(_rightOf(_cell($currencyLong))));
Q4) Narayan says that Sahi automatically waits if the server response time is not too long and always waits for Ajax requests. In my web app, some values are entered and a button is clicked to calculate interest. The same page is reloaded to reflect the new value (not Ajax). Since it's only a matter of seconds, there's no issue. However, how long should the response take before it becomes an issue?
Q2)
Q3) The code above could help here as well. Just collect the cells in the table and loop through the cells until cell = _cell($currency) and use the following cell for your assertions. Alternatively you could do something like _cell($currency).parentElement.children($X) where $X should not change or _cell(1, _near(_cell($currency)))
Q4) The time can be set in your sahi.properties
Regards
Wormi