...">

How to get text in a table column using Selenium RC?

I have a table that looks like this:

<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 extract Value1a, Value1b and Value1c? Can I use selenium.getText (...) or storeText (...)? If so, what is the correct xpath I should use? Suppose a table cannot be modified. Thanks!

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

it will be

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

etc.

Help text for getTable

getTable (tableCellAddress) Arguments:

  • tableCellAddress - cell address, for example. "Foo.1.4"

    Returns: text from the specified cell

    Gets text from a table cell. The syntax is cellAddress tableLocator.row.column, where the row and beginning of the column are 0.

+6
source

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++; } 

The result will contain all the listed values. Hope this helps !!!

+3
source

selenium.gettable (XPath)

0
source

Source: https://habr.com/ru/post/908386/


All Articles