0

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.

Community
  • 1
  • 1
megan
  • 305
  • 1
  • 6
  • 18
  • what are the values? you want let me know.. So that I can help you out. – Arup Rakshit Jun 28 '13 at 14:42
  • `m-N` value for *id* are you checking or *class*? – Arup Rakshit Jun 28 '13 at 14:48
  • Checking the background color still. The has the background-color applied to it. I need to find and test that the cells containing m-N have truly changed color. I know now how to check the color changed (thank you) but I am having trouble locating these specific cells. – megan Jun 28 '13 at 14:53
  • I added the xpath I have come up with so far. Though the answer does not have to be xpath. – megan Jun 28 '13 at 14:56
  • there are two `td` as I can see ` `. Which one you want to access? Edit your post with specific need,so that I can give you proper solution. Which part of the html you provided will be having dynamic values? – Arup Rakshit Jun 28 '13 at 15:08
  • The html you have provided is heavily confusing.. give the needed part only. – Arup Rakshit Jun 28 '13 at 15:14
  • I will keep in mind. I will be studying this weekend and will post better questions in the future. – megan Jun 28 '13 at 16:42

1 Answers1

1

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 ' )]"
hr_117
  • 9,589
  • 1
  • 18
  • 23
  • This does access it! I guess I have to brush up on how to properly construct xpaths. I thought my situation was so different. I'm still curious, if I wanted to go through each element that contains 'm-N' what should I do? – megan Jun 28 '13 at 14:59
  • Sorry I do not know how to iterate with ruby (what you seem to use) over the xpaht result. – hr_117 Jun 28 '13 at 15:09