xpath address where td not containing span Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of xpath address where td not containing span without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I want the xpath of only td that don’t have span with class “nop”, in below example the first, second and fifth td:

<tr>
  <td></td>
  <td></td>
  <td><span class="nowrp"></td>
  <td><span class="nowrp"></td>
  <td></td>
</tr>

I tried this but didn’t worked:

//td[not(contains(@class, 'nowrp'))]

and this didn’t worked as well:

//td[not(contains(span, (@class, 'nowrp')))]

Answer

First, your xml is invalid. But assuming you fix it like so:

<tr>
  <td>1</td>
  <td>2</td>
  <td><span class="nowrp">3</span></td>
  <td><span class="nowrp">4</span></td>
  <td>5</td>
</tr>

this xpath expression

//td[not(contains(./span/@class, 'nowrp'))]

should output:

 1
 2
 5
We are here to answer your question about xpath address where td not containing span - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji