megan
megan

Reputation: 315

Ruby/Selenium Access property of cells in a table that frequently changes

I am trying to access a property of cells in a table.

<table id="m-103" class="m-row" cellspacing="0">
<a name="2"></a>
<table id="m-108" class="m-row " cellspacing="0">
<a name="3"></a>
<table id="m-191" class="m-row " cellspacing="0">
 <tbody>
   <tr>
    <td class="m-st">
    <td class="m-jk m-N">
    </td>
</td>
</tr>
</tbody>
</table>

This is the xpath I have so far

 .//*[@class='m-row']/tbody/tr/td[@class='m-jk']

but it will only access the cells in the first table.

  1. I am interested in the m-N class value. Not every table has the m-N value. I'm only interested in the ones that do. Is there a way to only check tables that contain "m-N" or do I have to go through each one and check and if so how do I do that? I know now only how to go to specific paths so I have no clue how to iterate through each table.

  2. How do I access the second class value "m-N"? Every css or xpath Iv'e used does not work, and again they are only for a predetermined table.

I saw an answer but the person was using jquery? Is this something I should learn and use as well? Can I if I'm using Ruby and Selenium?

How to get the second class name from element?

There are many more tables this is only 3 of them I'm showing for the example. Also the number of tables and cells changes frequently.

Upvotes: 0

Views: 647

Answers (1)

hr_117
hr_117

Reputation: 9627

To get the td elements which have a class attribute which contains m-N you can use the xpath function contains(). Try this:

"//td[contains(@class, 'm-N')]"

This could get a little bit more complex if there also other classes which contains 'm-N' like 'm-Nx'. Than you have to do something like this:

"//td[contains(concat( ' ', @class, ' '), ' m-N ' )]"

Upvotes: 1

Related Questions