How do I retrieve the text in a table column using Selenium RC?

懵懂的女人 提交于 2019-12-11 02:46:56

问题


I have a table that looks like the following:

<table class="theClass">
<tr>
   <td class="anotherClass"><strong>Label1:</strong></td>
   <td colspan="3">Value1a<br/>Value1b<br/>Value1c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label2:</strong></td>
   <td colspan="3">Value2a<br/>Value2b<br/>Value2c</td>
</tr>

<tr>
   <td class="anotherClass"><strong>Label3:</strong></td>
   <td colspan="3">Value3a<br/>Value3b<br/>Value3c</td>
</tr>
</table>

How can I use Selenium RC to retrieve Value1a, Value1b, and Value1c ? Can I use selenium.getText(...) or storeText(...)? If so, what is the proper xpath I should use? Please assume that the table cannot be changed. Thanks!


回答1:


it would be

string value1 = selenium.getTable("table.1.2");
string value2 = selenium.getTable("table.2.2");

and so on.

The help text for getTable is

getTable(tableCellAddress) Arguments:

  • tableCellAddress - a cell address, e.g. "foo.1.4"

    Returns: the text from the specified cell

    Gets the text from a cell of a table. The cellAddress syntax tableLocator.row.column, where row and column start at 0.




回答2:


Check this,

            int i =1;

       while(selenium.isElementPresent("//table/tbody/tr["+i+"]/td[2]")){
           System.out.println(selenium.getText("//table/tbody/tr["+i+"]/td[2]"));
           i++;
       }

Result will contain all the values listed.Hope it helps!!!




回答3:


String value1 = selenium.getText("//tr[1]/td[1]/strong[contains(text(), Label1:')]/../../td[2]");



回答4:


selenium.gettable(xpath)



来源:https://stackoverflow.com/questions/2348028/how-do-i-retrieve-the-text-in-a-table-column-using-selenium-rc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!