Lulu
Lulu

Reputation: 79

How to read html table's record/row/cells using webdriver

I have a search result displayed on the web page, represented by one record in a table format. The code behind it :

</table>
<table id="highVolumeSearchResults_group" class="highVolumeSearchResults">
  <thead>
  <tbody>
     <tr>
       <td class="title letter" rowspan="1">W</td>
       <td>
          <a id="group-name-244" href="/Portal/Workgroup/Details?id=244">WorkGroup_Cats</a>
       </td>
       <td>0</td>
       <td>12/28/2012 4:14:01 PM</td>
       <td>
          <select id="244" onchange="CommitAction(244, this.options[this.selectedIndex].value, this)">
             <option value="">------</option>
             <option value="edit">Edit Users</option>
             <option value="rename">Rename</option>
             <option value="delete">Delete</option>
          </select>
       </td>
    </tr>
</tbody>
</table>

I am trying to automate (in C#) 'Rename' and/or 'Delete' options, so basically looking for a way to select/Click 'Rename' or 'Delete' option in a dropdown of cell with id "244". The problem with that id is that it is dynamically generated, once I delete that row and create a new one - a new id gets assigned to a newly created record. My dropdown located in a 5th column of identified record(row).

This is how I started implementing :

ICollection<IWebElement> table = driver.FindElements(By.Id("highVolumeSearchResults_group")); 
List<IWebElement> elements = table.ToList();

string test = elements[1].FindElement(By.XPath("//tbody/tr/td[4]")).Text; 
test.FindElement(By.

It doesn't seem to work for me (and Selenium IDE identifies the element only with Id at this point). Can someone please help, I am lost.

Upvotes: 0

Views: 7195

Answers (1)

Santoshsarma
Santoshsarma

Reputation: 5667

Try this

ICollection<IWebElement> table = driver.FindElements(By.XPath("//table[@id='highVolumeSearchResults_group']//tr/td")); 
List<IWebElement> elements = table.ToList();

Now iterate that list to get each td content. (text inside td)

To get the all option from that drop down as list use this ( It is the implementation in java selenium binding)

new Select(driver.findElement(By.xpath("//table[@id='highVolumeSearchResults_group']//tr/td/select")).getOptions();

in C# may be something like this

new SelectElement(driver.FindElement(By.XPath("//table[@id='highVolumeSearchResults_group']//tr/td/select")).Options;

P.S : I don't much aware of C# implementation for selenium.

Upvotes: 2

Related Questions