Carpe
Carpe

Reputation: 89

how to find parent element that has specific child using By.xpath()?

Recently i've been scrapping by using selenium-webdriver in nodejs for a few days. so i have to find element has specific child element but i don't know how find it.

i have used following operator but it doesn't work

By.xPath("tr[contains(@class, 'datetime2')]")

following html

<table>
  <tbody>
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        20:00
      </td>
    <tr>
    
    <tr></tr>
    
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        21:00
      </td>
    <tr>
    
    <tr style="bacrgound-color:#eee">
      <td class="datetime2">
        22:00
      </td>
    <tr>
    
    <tr></tr>
  </tbody>
</table>

i need to find only 'tr' that include element <td class="datetime2">. not <tr></tr>

how find this element By using By.xpath()?? please help me

Upvotes: 1

Views: 531

Answers (1)

Murthi
Murthi

Reputation: 5347

please try with following x-path.

//tr[td[@class='datetime2']]

Upvotes: 3

Related Questions