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.

looking for a best solution to get text of any cell in a table

ligangligang Members
edited November -1 in Sahi - Open Source
In my test, I want to get the text of any cell in a table, any suggestions ?

For example, I want to get the text "User One", how can I do ?

<table>
<tr>
<td>Name</td>
<td>Delete</td>
<td>Status</td>
</tr>
<tr>
<td>User One</td>
<td id="del1"><a href="/deleteUser?id=1">delete</a></td>
<td>Active</td>
</tr>
<tr>
<td>User Two</td>
<td id="del2"><a href="/deleteUser?id=2">delete</a></td>
<td>Inactive</td>
</tr>
</table>

Comments

  • SumitraSumitra Members
    Hi ligang,

    You can use _getText(element) API to get the text of any cell in a table.

    For more details:

    http://sahi.co.in/w/all-apis

    Regards
    Sumitra
  • ligangligang Members
    Hi, Sumitra

    I know getText, but I don't know how to locate one cell in the table.

    I notice there are two ways to locate one cell

    _cell(identifier[, domRelation])
    _cell(tableElement, rowText, colText)

    But both need to know the text firstly, it is infinite loop, Do I make a misunderstanding ?
  • SumitraSumitra Members
    Hi ligang,

    You can use:

    _getText(0,_near(_link("delete")),_under(_cell("Name")));

    Regards
    Sumitra
  • ligangligang Members
    Hi, sumitra

    thanks for your quick reply, I 'll try your solution, if your example is Java format, It is helpful for me.

    I have a little confuse for java format.
  • narayannarayan Administrators
    Hi Ligang,

    browser.cell(browser.table("tableId"), rowIndex, colIndex)

    also works.

    Regards,
    Narayan
  • ligangligang Members
    Hi, Narayan

    You help me solve my problem again. I though index can't work , but it can . thank you so much.
  • ligangligang Members
    Oh, sorry, just now I tried your , has the following error.

    error:_sahi.setServerVarPlain('___lastValue___Mon Jun 20 16:43:45 CST 2011', _getText(_cell(_table("dataTable[1]", 2, 2))))
    TypeError: object can't support "match" attribute or method
    No trace available
    at net.sf.sahi.client.Browser.executeStep(Browser.java:223)
    at net.sf.sahi.client.Browser.execute(Browser.java:190)
    at net.sf.sahi.client.Browser.fetch(Browser.java:478)
    at net.sf.sahi.client.Browser.getText(Browser.java:501)
  • ligangligang Members
    Sorry , It did work, I made a little mistake. Thanks again
This discussion has been closed.